[英]Linker error while compiling mexfunction with boost
我正在嘗試在mexfunctions中使用boost。
下面給出的是我的代碼
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");
}
我用下面的命令編譯它
mex main.cpp -LC:\Boost\1.55.0\VC\10.0\x64\stage\lib -IC:\Boost\1.55.0\VC\10.0\x64
然后我得到這個鏈接錯誤
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.
然后我再次使用
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
但是我仍然遇到同樣的錯誤。 我該如何解決?
編輯:
我可以在普通的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添加.lib,為unix添加.LIBEXT。
這是一個帶有真實路徑的示例:
mex main.cpp -IC:\boost_1_54_0 -LC:\boost_1_54_0\release -lthread
最后,在您的情況下,我建議嘗試:
mex main.cpp -IC:\Boost\1.55.0\VC\10.0\x64 -LC:\Boost\1.55.0\VC\10.0\x64\stage\lib -lthread
編輯:
我注意到定義BOOST_ALL_NO_LIB
也會BOOST_ALL_NO_LIB
幫助,因為刪除此定義后,我會再次收到錯誤。 要定義符號名稱,可以使用命令行選項-D
因此只需添加-DBOOST_ALL_NO_LIB
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.