0

我在 MATLAB 中编写 MEX 文件时遇到问题,该文件可以执行简单的线性运算,例如求矩阵的逆。我已经成功地使用 Visual Studio 2010 对矩阵求逆,并成功创建了一个 MEX 文件,因此我唯一遇到的问题是将这两个概念放在一起。我试图编译从 MathWorks 站点获得的 MEX 示例代码,但没有成功。

这是我尝试过的,

  1. 将我从 MathWorks 获得的文件(重命名)保存为 .c 扩展名,然后尝试在 MATLAB 中编译得到:

    创建库 C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.x 和对象 C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.exp eko1.obj:错误 LNK2019:未解析的外部符号dgesv 在函数 mexFunction eko1.mexw64 中引用:致命错误 LNK1120:1 未解决的外部

  2. 我也尝试将它编译为 .cpp 文件,但是由于它无法识别 memcpy 函数而发生错误。

  3. 由于这些不起作用,我编写了自己的程序,该程序使用了 LAPACK 库中的子例程 dgetrf 和 dgetri,但是发生了错误:

    c:\users\cit\documents\matlab\f2c.h(16):错误 C2371:“复杂”:重新定义;不同的基本类型 C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(39) :参见“复杂”的声明 c:\users\cit\documents\matlab\f2c.h(17):错误 C2371 :'doublecomplex':重新定义;不同的基本类型 C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(40) :参见“doublecomplex” eko2.cpp(29) 的声明:错误 C2057:预期的常量表达式 eko2.cpp(29):错误 C2466:无法分配常量大小 0 eko2.cpp(29) 的数组:错误 C2133:“ipiv”:未知大小 eko2.cpp(33):错误 C2664:“dgetrf”:无法从“整数 *”转换参数 1 to 'ptrdiff_t *' 指向的类型是不相关的;转换需要 reinterpret_cast,C-style cast 或 function-style cast eko2.cpp(34) : error C2664: 'dgetri' : cannot convert parameter 1 from 'integer *' to 'ptrdiff_t *' 指向的类型不相关;转换需要 reinterpret_cast、C-style cast 或 function-style cast

你们给我的任何帮助将不胜感激

提前致谢。

4

1 回答 1

0

Without any code to see what you've tried, it's hard to tell, but... in order to properly compile a mex file in matlab that depends on other libraries, you need to specify those libraries in the compile command. Use mex filename.c -v -l*libraryname*.lib. The -l switch indicates to the compiler that you are specifying a library that you want to include. If this library is not found, I would include the full path to the library in the command. I hope that provides you with some assistance. Using this methodology has been successful for me.

于 2012-06-24T06:33:55.107 回答