使用提升编译 mexfunction 时出现链接器错误

Linker error while compiling mexfunction with boost

本文关键字:链接 错误 mexfunction 编译      更新时间:2023-10-16

我正在尝试在 mexfunctions 中使用 boost。

下面是我的代码

主.cpp

#include <mex.h>
#include <boost/thread.hpp>   
#include <boost/date_time.hpp> 
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    mexPrintf("test boost");
}

我使用以下命令编译它

mex main.cpp -LC:Boost1.55.0VC10.0x64stagelib -IC:Boost1.55.0VC10.0x64

然后我得到这个链接错误

LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc100-mt-1_55.lib' 
C:PROGRA~1MATLABR2012ABINMEX.PL: Error: Link of 'main.mexw64' failed.

然后我再次编译使用,

mex main.cpp -LC:Boost1.55.0VC10.0x64stagelib -IC:Boost1.55.0VC10.0x64 -llibboost_thread-vc100-mt-s-1_55

但我仍然得到同样的错误。我该如何解决这个问题?

编辑:

我可以在普通的Visual Studio c ++项目中使用boost,没有任何问题。只有当我把它放在 mexfunction 中时,问题才会出现

我知道

这个问题现在已经很老了,但是我在 mex 上遇到了类似的问题,我不仅可以通过指定库目录搜索路径来解决它,还可以指定编译的库对象的名称。

为此,我使用了以下命令:

mex main.cpp -I<path/to/lib> -L<path/to/lib/objects> -l<object_name>

命令行选项 -l 用于告诉 mex 链接指定的对象库。然后,Mex将尝试查找添加到-l中的任何内容,并为Windows和.LIBEXT for unix.

这里有一个带有真实路径的示例:

mex main.cpp -IC:boost_1_54_0 -LC:boost_1_54_0release -lthread

最后,在您的情况下,我建议您尝试:

mex main.cpp -IC:Boost1.55.0VC10.0x64 -LC:Boost1.55.0VC10.0x64stagelib -lthread

编辑:

我注意到定义BOOST_ALL_NO_LIB也有帮助,因为当我删除此定义时,我再次收到错误。要定义符号名称,您可以使用命令行选项-D只需添加-DBOOST_ALL_NO_LIB