Linker error while compiling mexfunction with boost

Optimus

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

enwi

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bash error while compiling boost with cmake

From Dev

Error while compiling Boost.Bind

From Dev

Error while compiling Boost.Bind

From Dev

linker error while linking boost log tutorial (undefined references)

From Dev

Boost 1.59 linker error

From Dev

Boost Graph Library: Error while compiling with make_reverse_graph

From Dev

linker errors while compiling using makefile

From Dev

Inheritance in C++ not working. Linker error occured while compiling the below C++ code

From Dev

Boost-log linker error

From Dev

Linker Error when compiling with static library

From Dev

mingw+libarchive: cross compiling linker error

From Dev

Error while compiling in matlab

From Dev

Error while compiling AIDL

From Dev

Runtime error while compiling

From Dev

Error while compiling in for loop

From Dev

Visibility linker warnings when compiling iOS app that uses Boost

From Dev

Error compiling Boost.Log

From Dev

Linker error with Boost, referenced in discarded section

From Dev

Linker issue while compiling source using hunspell library

From Dev

Gradle Error while compiling renderscript

From Dev

Fatal error with jsoncpp while compiling

From Dev

Error while compiling PortAudio examples

From Dev

Error while compiling in cmd but not in Netbeans

From Dev

syntax error while compiling sqlite

From Dev

Error while compiling a file in ubuntu

From Dev

error: expected identifier while compiling

From Dev

Linker error: Boost.Chrono to Boost.Timer

From Dev

Linker error: Boost.Chrono to Boost.Timer

From Dev

"undefined symbols for architecture" linker error when compiling a Qt tutorial