سؤال

I'm trying to use boost in mexfunctions.

Given below is my code

main.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");

}

I compile it using the below command

mex main.cpp -LC:\Boost\1.55.0\VC\10.0\x64\stage\lib -IC:\Boost\1.55.0\VC\10.0\x64

Then i get this linking error

LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc100-mt-1_55.lib' 

C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Link of 'main.mexw64' failed.

Then I compiled again using,

mex main.cpp -LC:\Boost\1.55.0\VC\10.0\x64\stage\lib -IC:\Boost\1.55.0\VC\10.0\x64 -llibboost_thread-vc100-mt-s-1_55

But still I get the same error. How can I solve this ?

EDIT :

I can use boost in a normal visual studio c++ project without any issue. The issue only comes when I put it in a mexfunction

هل كانت مفيدة؟

المحلول

I know this question is pretty old now, but I've had a similar issue with mex and I could solve it by specifying not only the library directory search path, but also the name of the compiled library object.

For that I used the following command:

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

The command line option -l is used to tell mex to link a specified object library. Mex will then try to find whatever is added to -l and will append .lib for windows and .LIBEXT for unix.

Here an example with real paths:

mex main.cpp -IC:\boost_1_54_0 -LC:\boost_1_54_0\release -lthread

And finally in your case I would suggest trying:

mex main.cpp -IC:\Boost\1.55.0\VC\10.0\x64 -LC:\Boost\1.55.0\VC\10.0\x64\stage\lib -lthread

EDIT:

I noticed that defining BOOST_ALL_NO_LIB also helps, because when I remove this define I get the error again. To define a symbol name you can use the command line option -D so just add -DBOOST_ALL_NO_LIB

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top