如何在mex文件中使用CLAPACK,BLAS或LAPACK? [英] How can I use CLAPACK,BLAS or LAPACK in a mex file?

查看:198
本文介绍了如何在mex文件中使用CLAPACK,BLAS或LAPACK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am having trouble writing a MEX file in MATLAB that can perform a simple linear operation such as taking the inverse of a matrix. I have successfully managed to take the inverse of a matrix using Visual Studio 2010 and have successfully created a MEX file hence the only thing I am having trouble is getting these two concepts together. I have tried to compile a MEX example code that I got from the MathWorks site but with no luck.

这是我尝试过的,

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

  1. Saved the file (renamed it) I got from MathWorks as .c extension and then tried to compile it in MATLAB got:

创建库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 尚未解决的外部因素

Creating library C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.x and object C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.exp eko1.obj : error LNK2019: unresolved external symbol dgesv referenced in function mexFunction eko1.mexw64 : fatal error LNK1120: 1 unresolved externals

  • 我也尝试将其编译为.cpp文件,但是发生了错误,因为它无法识别memcpy函数.

  • Also I tried to compile it as a .cpp file however an error occurred because it didnt recognize the memcpy function.

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

    Since these didn't work I wrote my own program that used the subroutines dgetrf and dgetri from the LAPACK library however an error occured:

    c:\ users \ cit \ documents \ matlab \ f2c.h(16):错误C2371:'complex': 重新定义;不同的基本类型 C:\ Program Files \ MATLAB \ R2011b \ extern \ include \ lapack.h(39):参见'complex'的声明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从'integer *'转换为'ptrdiff_t *' 指向的类型无关.转换需要reinterpret_cast,C样式强制转换或函数样式强制转换eko2.cpp(34): 错误C2664:"dgetri":无法将参数1从整数*"转换为 'ptrdiff_t *' 指向的类型无关.转换需要reinterpret_cast,C样式强制转换或函数样式强制转换

    c:\users\cit\documents\matlab\f2c.h(16) : error C2371: 'complex' : redefinition; different basic types C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(39) : see declaration of 'complex' c:\users\cit\documents\matlab\f2c.h(17) : error C2371: 'doublecomplex' : redefinition; different basic types C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(40) : see declaration of 'doublecomplex' eko2.cpp(29) : error C2057: expected constant expression eko2.cpp(29) : error C2466: cannot allocate an array of constant size 0 eko2.cpp(29) : error C2133: 'ipiv' : unknown size eko2.cpp(33) : error C2664: 'dgetrf' : cannot convert parameter 1 from 'integer *' to 'ptrdiff_t *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast eko2.cpp(34) : error C2664: 'dgetri' : cannot convert parameter 1 from 'integer *' to 'ptrdiff_t *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

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

    Any help you guys give me would be extremely appreciated

    谢谢.

    推荐答案

    没有任何代码可以查看您尝试过的内容,很难分辨,但是...为了在matlab中正确编译依赖于其他库,则需要在compile命令中指定这些库.使用mex filename.c -v -l*libraryname*.lib. -l开关向编译器指示您正在指定要包括的库.如果找不到该库,我将在命令中包含该库的完整路径.希望能为您提供帮助.使用这种方法学对我来说是成功的.

    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.

    这篇关于如何在mex文件中使用CLAPACK,BLAS或LAPACK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆