在 Ubuntu OS 中的 Matlab 2017a 上切换编译器
Switch compiler on Matlab 2017a in Ubuntu OS
我正在运行一个需要cpp编译器的脚本。我在Windows和Ubuntu上使用MATLAB。在窗口上,具有:
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
但我仍然得到相同的结果。
问题是你使用int
而不是mwSize
维度数组:
const int *dim; // image dimensinos
int dtree[2]; // tree dimensions
这些应该是:
const mwSize *dim; // image dimensinos
mwSize dtree[2]; // tree dimensions
MathWorks 的描述是:
mwSize 是表示大小值(如数组维度(的类型。使用此函数可实现跨平台灵活性。默认情况下,mwSize 等效于 C 中的 int。
使用 mex -largeArrayDims 开关时,mwSize 相当于 C 中的size_t。
所以问题是在一个平台上使用int*
是合法的,而在另一些平台上可能是 size_t*
.但是,使用总是正确的 mwSize*
,因为这是便携式解决方案。
作为旁注,我会这样写第一行:
mwSize const* dim; // image dimensinos
恕我直言,这种方式更易于阅读,链接到示例
正如乔纳斯在上面的答案中指出的那样,最好使用 mwSize。
在 64 位和 32 位系统之间切换时也可能导致相同的问题。 例如这个线程
在这种情况下,您还可以尝试使用 32 位兼容性标志编译 mex:
mex -DMX_COMPAT_32 file.cpp
这个解决方案在我的情况下有效。
相关文章:
- C/C++编译器通常会删除重复的库吗
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- Win32编译器选项和内存分配
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 在线编译器中的分段C++没有打印消息
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- C/C++预处理器是否可以检测一些编译器选项
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 我需要知道编译器如何在cpp中使用析构函数
- 编译器如何区分std::vector的构造函数
- CLANG 编译器 说:变量"PTR"可能未初始化
- 告诉c++编译器该参数没有别名
- 使用仅使用一次的变量调用的复制构造函数.这可能是通过调用move构造函数进行编译器优化的情况吗
- 为什么所有C++编译器都会崩溃或挂起此代码
- 编译器如何在使用SFINAE的函数和标准函数之间确定两者是否可行
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 在 Ubuntu OS 中的 Matlab 2017a 上切换编译器