简体   繁体   English

在Ubuntu OS中使用Matlab 2017a切换编译器

[英]Switch compiler on Matlab 2017a in Ubuntu OS

I am running a script that needs a cpp compiler. 我正在运行需要cpp编译器的脚本。 I'm using MATLAB on both Windows and Ubuntu. 我在Windows和Ubuntu上都使用MATLAB。 On windows, with: 在窗户上,有:

MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation.

i have no problem. 我没有问题。

On Ubuntu, i have: 在Ubuntu上,我有:

MEX configured to use 'g++' for C++ language compilation.

and when i try to compile me .cpp files i get this error: 当我尝试编译我的.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

I installed mingw-w64, by sudo apt-get install mingw-w64 but i still get the same result. 我安装了mingw-w64,通过sudo apt-get install mingw-w64但我仍然得到相同的结果。

The problem is that you use int and not mwSize for you dimension arrays: 问题是您为维度数组使用int而不是mwSize

const int *dim; // image dimensinos
int dtree[2];   // tree dimensions

These should be: 这应该是:

const mwSize *dim; // image dimensinos
mwSize dtree[2];   // tree dimensions

The description from MathWorks is: MathWorks的描述是:

mwSize is a type that represents size values, such as array dimensions. mwSize是一种表示大小值的类型,例如数组维度。 Use this function for cross-platform flexibility. 使用此功能可实现跨平台灵活性。 By default, mwSize is equivalent to int in C. 默认情况下,mwSize等效于C中的int。

When using the mex -largeArrayDims switch, mwSize is equivalent to size_t in C. 使用mex -largeArrayDims开关时,mwSize相当于C中的size_t。

So the issue is that on one platform it is legal to use int* and on others it could be size_t* . 所以问题是在一个平台上使用int*是合法的,而在其他平台上它可能是size_t* However, it always correct to use mwSize* , since this is the portable solution. 但是,使用mwSize* 始终是正确的,因为这是便携式解决方案。

As a side note I would write the first line like this: 作为旁注,我会像这样写第一行:

mwSize const* dim; // image dimensinos

This way is IMHO simpler to read, link to examples 这种方式是恕我直言更容易阅读, 链接到示例

As Jonas pointed out in the answer above, it is better to use mwSize. 正如Jonas在上面的答案中指出的那样,最好使用mwSize。

The same problem might also be caused while shifting between 64 and 32 bit systems. 在64位和32位系统之间切换时也可能导致同样的问题。 eg this thread 例如这个帖子

In that case you can also try compiling mex with 32-bit compatibility flag : 在这种情况下,您还可以尝试使用32位兼容性标志编译mex:

 mex -DMX_COMPAT_32 file.cpp

This solution worked in my case. 这种解决方案适用于我的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM