ler*_*rei 3 macos matlab fortran mex gfortran
我需要从 MATLAB 中调用一些 Fortran 代码。我做了一些研究并阅读了有关mex命令以及如何使用它的信息。遗憾的是,我已经无法让 Fortran 编译器正常工作。
首先,这是我的设置:
根据 MATLAB 文档,我可以mex -setup FORTRAN用来准备mex从 Fortran 构建 mex 文件。但是,在详细模式下运行命令会产生以下输出:mex -setup -v FORTRAN
Verbose mode is on.
... Looking for compiler 'Intel Fortran Composer XE' ...
... Looking for environment variable 'IFORT_COMPILER16' ...No.
... Looking for environment variable 'IFORT_COMPILER15' ...No.
... Looking for environment variable 'IFORT_COMPILER14' ...No.
... Looking for environment variable 'IFORT_COMPILER13' ...No.
... Executing command 'which ifort' ...No.
Did not find installed compiler 'Intel Fortran Composer XE'.
Error using mex
No supported compiler or SDK was found. For options, visit
http://www.mathworks.com/support/compilers/R2016b/maci64.html.
Run Code Online (Sandbox Code Playgroud)
通过链接,可以看到 MATLABGNU gfortran 4.9.x在 Linux 上确实支持。然而,在 Mac 上,只有英特尔的商业编译器被列为受支持。这mex似乎也是正在寻找的东西。
由于 Mac 也可以gfortran用来编译 Fortran 代码,我认为它可以与 MATLAB 一起使用。我也在 google 上搜索了很多,在 MathWorks 论坛上发现了类似这样的问题,这表明 MATLAB 应该能够使用gfortran,即使在 Mac 上也是如此。
这就是我认为奇怪的地方,我的 MATLAB 甚至没有寻找gfortran编译器。它所做的只是寻找英特尔编译器,找不到,然后抛出上述错误消息。
关于我的gfortran安装。它肯定是 4.9.2(在 Linux 下被列为支持),which gfortran返回/usr/local/bin并且我可以通过终端成功编译程序。
顺便说一下,mex -setup ANY成功列出了 C 和 C++ 的编译器,但没有列出 Fortran。
MEX configured to use 'Xcode with Clang' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
MEX configured to use 'Xcode Clang++' for C++ language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different C compiler, select one from the following:
Xcode with Clang mex -setup:'/Users/Lennart/Library/Application Support/MathWorks/MATLAB/R2016b/mex_C_maci64.xml' C
Xcode Clang++ mex -setup:'/Users/Lennart/Library/Application Support/MathWorks/MATLAB/R2016b/mex_C++_maci64.xml'
Run Code Online (Sandbox Code Playgroud)
我还查看.xml了上次输出最后提到的那些文件。没有任何与 Fortran 相关的文件,我自己也无法成功编写一个。我什至不确定这是否是问题所在......
所以简单地说我的问题是:我怎样才能让 MATLAB 实际寻找,然后当然也找到我的gfortran编译器来使用它来编译mex文件?
感谢你的帮助!
感谢 hsuyaa 和提供的链接,我能够解决我的问题。由于它需要自己进行更多实验,因此我想发布我究竟是如何让 gfortran 工作的。
查看此链接和已接受的答案。尽管 MathWorks 团队明确声明这些说明是专门为 xCode 7.0 和 MATLAB R2015b 编写的,但我得到的一切都适用于 xCode 8.1、MATLAB R2016b 和 macOS Sierra 10.12。
如前所述,MATLAB 似乎将编译器配置详细信息存储在 .xml 文件中。您可以通过输入在MATLAB中找到该目录
cd( fullfile( matlabroot, 'bin', 'maci64', 'mexopts' ) );
Run Code Online (Sandbox Code Playgroud)
我之前确实执行了 MATLAB 的全新安装,但在那个位置,只有三个文件,一个用于 Clang,一个用于 Clang++,一个用于英特尔的 Fortran。gfortran 一个只是丢失了。
MathWorks 的解决方案作者将所有这些 .xml 文件附加到他的帖子中。我下载了文件并将 gfortran.xml 复制到上述文件夹中。这获得了部分成功,因为它使 MATLAB 在运行 mex 设置时实际上寻找 gfortran。
但是,由于文件不是最新的,我不得不添加几行。我不太明白配置文件是如何工作的,但我注意到有些行指的是旧的 macOS 版本。下载上面链接后面的文件 gfortran.xml,然后添加以下内容:
随处可见
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk" />
Run Code Online (Sandbox Code Playgroud)
或者
<cmdReturns name="find $$ -name MacOSX10.11.sdk" />
Run Code Online (Sandbox Code Playgroud)
还添加
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk" />
Run Code Online (Sandbox Code Playgroud)
或者
<cmdReturns name="find $$ -name MacOSX10.12.sdk" />
Run Code Online (Sandbox Code Playgroud)
macOS 10.12 是 Sierra。保存文件并mex -setup FORTRAN再次运行成功识别 gfortran 并将其设置为 mex 的 fortran 编译器。
| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |