我正在運行需要cpp編譯器的腳本。我在Windows和Ubuntu上都使用MATLAB。在windows上,用:在Ubuntu OS的Matlab 2017a上編譯開關編譯器
MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation.
我沒問題。
在Ubuntu上,我有:
MEX configured to use 'g++' for C++ language compilation.
,當我嘗試編譯我.cpp文件,我得到這個錯誤:
Error using mex
/home/christosandsoren/17gr10409/deformable_models/texture_functions/build_km_tree.cpp: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:
/home/christosandsoren/17gr10409/deformable_models/texture_functions/build_km_tree.cpp:380:9: error: cannot convert ‘const size_t* {aka const long unsigned int*}’ to ‘const
int*’ in assignment
dim = mxGetDimensions(prhs[0]);
^
/home/christosandsoren/17gr10409/deformable_models/texture_functions/build_km_tree.cpp:402:68: error: cannot convert ‘int*’ to ‘const size_t* {aka const long unsigned
int*}’ for argument ‘2’ to ‘mxArray* mxCreateNumericArray(size_t, const size_t*, mxClassID, mxComplexity)’
plhs[0] = mxCreateNumericArray(2, dtree, mxDOUBLE_CLASS, mxREAL);
^
Error in compile_mex_functions (line 3)
mex build_km_tree.cpp % based on Euclidean distance
我安裝的MinGW-W64,由sudo apt-get install mingw-w64
但我仍然得到相同的結果。
看來你在Windows上使用32位(儘管MinGW64名稱),並在Linux上使用64位。由於'size_t'是32位或64位寬,具體取決於系統。 – Jonas
您應該將'dtree'定義爲'size_t *'而不是'int *'。 – Jonas
謝謝你的回覆, 我做了你建議的改變,我擺脫了最後一個錯誤。雖然: 錯誤使用mex build_km_tree.cpp:函數'void mexFunction(int,mxArray **,int,const mxArray **)': build_km_tree.cpp:380:34:錯誤:無法轉換'const size_t在assignment' * {又名const的長期無符號整型*}」到 'const int的*' 還是有的... 情況下你需要它: '無效mexFunction(INT nlhs,mxArray * plhs [], int nrhs,const mxArray * prhs [])' –