MATLAB mex不在macOS上寻找编译器gfortran [英] MATLAB mex not looking for compiler gfortran on macOS

查看:601
本文介绍了MATLAB mex不在macOS上寻找编译器gfortran的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从MATLAB内部调用一些Fortran代码。我做了一些研究并阅读了 mex 命令以及如何使用它。



首先,这里是我的设置:




  • macOS Sierra 10.12.1(最新版本)

  • MATLAB R2016b(最新版本)

  • gfortran 4.9.2 (通过官方GNU站点的.dmg安装)



根据MATLAB文档,我可以使用 mex - 设置FORTRAN 以准备 mex ,以便从Fortran构建mex文件。但是,以详细模式运行该命令会产生以下输出: mex -setup -v FORTRAN

 详细模式开启。 
...寻找编译器'英特尔Fortran Composer XE'...
...寻找环境变量'IFORT_COMPILER16'...没有。
...寻找环境变量'IFORT_COMPILER15'...不。
...寻找环境变量'IFORT_COMPILER14'...没有。
...寻找环境变量'IFORT_COMPILER13'...不。
...执行命令'哪个ifort'...没有。
未找到已安装的编译器'Intel Fortran Composer XE'。
使用mex
的错误未找到支持的编译器或SDK。有关选项,请访问
http://www.mathworks.com/support/compilers/R2016b/maci64.html。

link ,可以看到MATLAB在Linux上支持 GNU gfortran 4.9.x 。但是,在Mac上,只有英特尔的商业编译器被列为支持。这就是 mex 似乎也在寻找的东西。因为Mac也可以使用 gfortran 来编译Fortran代码,所以我认为它可以使它工作。 用MATLAB。我也搜索了很多,发现像这个问题,这表明MATLAB即使在Mac上也应该可以使用 gfortran



<这就是我认为的奇怪,我的MATLAB甚至没有找到一个 gfortran 编译器。它只是寻找英特尔编译器,找不到一个,然后抛出上述错误信息。



关于我的 gfortran 安装。它肯定是4.9.2(在Linux下被列为支持),其中gfortran 返回 / usr / local / bin 和我可以通过终端成功编译程序。



顺便说一句, mex -setup ANY 成功列出了编译器用于C和C ++,但不支持Fortran。

  MEX配置为使用'Xcode with Clang'进行C语言编译。 
警告:MATLAB C和Fortran API已更改为支持2 ^ 32-1元素以上的MATLAB
变量。在不久的将来
您将被要求更新您的代码以利用
新的API。您可以在以下网址找到更多关于此的信息:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html。
MEX配置为使用'Xcode Clang ++'进行C ++语言编译。
警告:MATLAB C和Fortran API已更改为支持2 ^ 32-1元素以上的MATLAB
变量。在不久的将来
您将被要求更新您的代码以利用
新的API。您可以在以下网址找到更多关于此的信息:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html。

要选择不同的C编译器,请从以下选择一个:
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'

我还查看了最后一次输出最后提到的那些 .xml 文件。没有任何与Fortran有关的文件,我无法成功自己写一个。我甚至不知道这是否是问题所在......



因此,简单地说我的问题是:我怎样才能让MATLAB真正找到,然后当然也找到我的 gfortran 编译器用它来编译 mex 文件?



<感谢您的帮助!

解决方案

感谢hsuyaa和提供的链接,我能够解决我的问题。因为它需要我自己进行更多的实验,所以我想发布我能够让gfortran工作的方式。



看看这个链接和接受的答案。尽管MathWorks团队明确指出,这些指令是专门为xCode 7.0和MATLAB R2015b编写的,但我已将所有内容与xCode 8.1,MATLAB R2016b和macOS Sierra 10.12配合使用。

如前所述,MATLAB似乎将编译器配置细节存储在.xml文件中。你可以通过输入

  cd(fullfile(matlabroot,'bin','maci64','mexopts' )); 

我之前执行过全新的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/> 

 < cmdReturns name =find $$ -name MacOSX10.11.sdk/> 

也加入

 < dirExists name =$$ / Platforms / MacOSX.platform / Developer / SDKs / MacOSX10.12.sdk/> 

 < cmdReturns name =find $$ -name MacOSX10.12.sdk/> 

macOS 10.12是Sierra。保存文件并运行 mex -setup FORTRAN 再次成功识别gfortran并将其设置为mex的fortran编译器。


I need to call some Fortran code from within MATLAB. I did some research and read about the mex command and how to use it. Sadly I'm already failing at getting the Fortran compiler to work.

First of all, here's my setup:

  • macOS Sierra 10.12.1 (latest version)
  • MATLAB R2016b (latest version)
  • gfortran 4.9.2 (installed via .dmg from official GNU site)

According to the MATLAB documentation, I can use mex -setup FORTRAN to prepare mex for building a mex-file from Fortran. However, running the command in verbose mode yields the following output: 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.

Following the link, one can see that MATLAB does support GNU gfortran 4.9.x on Linux. On Mac however, only Intel's commercial compilers are listed as supported. That's what mex seems to be looking for as well.

Since Mac can also use gfortran to compile Fortran code I thought it'd be possible to get it to work with MATLAB. I've also googled alot and found questions like this one on the MathWorks forum, which suggests that MATLAB should be able to use gfortran, even on Mac.

That's what I think is strange, my MATLAB isn't even looking for a gfortran compiler. All it does is look for an Intel compiler, can't find one and then throws above stated error message.

Regarding my gfortran installation. It is definitely 4.9.2 (which is listed as supported under Linux), which gfortran returns /usr/local/bin and I can successfully compile programs via Terminal.

By the way, mex -setup ANY successfully lists the compilers for C and C++ but no 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'

I also had a look at those .xml files mentioned at the very end of the last output. There was no file for anything having to do with Fortran and I wasn't able to successfully write one myself. I'm not even sure whether that's the problem...

So simply put my question is: How can I get MATLAB to actually look for and then of course also find my gfortran compiler to use it to compile mex files?

Appreciate your help!

解决方案

Thanks to hsuyaa and the provided link I was able to resolve my problem. As it needed some more experimenting by myself, I'd like to post how exactly I was able to get gfortran to work.

Look at this link and the accepted answer. Although the MathWorks Team explicitly states that the instructions are specifically written for xCode 7.0 and MATLAB R2015b, I got everything to work with xCode 8.1, MATLAB R2016b and macOS Sierra 10.12.

MATLAB seems to be storing the compiler configuration details in .xml-files as mentioned before. You can find the directory in MATLAB by entering

cd( fullfile( matlabroot, 'bin', 'maci64', 'mexopts' ) );

I did perform a fresh install of MATLAB before but at that location, only three files where located, one for Clang, one for Clang++, one for Intel's Fortran. The gfortran one was simply missing.

The solution author at MathWorks appended all of these .xml-files to his post. I downloaded the files and copied gfortran.xml to the above mentioned folder. This granted partial success in that it made MATLAB actually look for gfortran when running the mex setup.

However, since the files are not up-to-date, I had to add a few lines. I don't exactly understand how the configuration files work, but I noticed that some lines where referring to older macOS versions. Download the file gfortran.xml behind the above link and then add the following:

Wherever you see

<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk" />

or

<cmdReturns name="find $$ -name MacOSX10.11.sdk" />

also add

<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk" />

or

<cmdReturns name="find $$ -name MacOSX10.12.sdk" />

macOS 10.12 is Sierra. Saving the file and running mex -setup FORTRAN again successfully identified gfortran and set it as the fortran compiler for mex.

这篇关于MATLAB mex不在macOS上寻找编译器gfortran的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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