从英特尔Fortran调用Matlab(Linux) [英] Call Matlab from Intel Fortran (Linux)

查看:316
本文介绍了从英特尔Fortran调用Matlab(Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我编写的一个Matlab程序集成到一些Fortran代码中。我试图按照Mathworks的示例 provides 。但是我无法编译它,因为我找不到它所请求的头文件。



有人知道有人让它在Linux上工作的例子使用英特尔编译器。我认为这可能是问题的一部分,因为Matlab只支持Linux上的GNU Fortran。



我意识到这是一个简单的问题,我只是不明白如何在编译比包含已定义路径的多个文件更复杂的任何事情上做任何事情。

m目前使用的是OS X,所以我只能提供OS X的输出,但是由于Unix的基础,一切都应该轻松地转移到Linux上。我也没有OS X上的英特尔Fortran编译器(只有C / C ++编译器)。




注意:根据您的MATLAB安装目录,您需要将您用于系统正确路径的路径替换掉。




这个问题并非特定于英特尔编译器,我也收到GCC Fortran编译器的错误。

  $ gfortran fengdemo.F 
fengdemo.F:1:0:

#includefintrf.h
^
致命错误:fintrf.h:No这样的文件或目录
编译终止。

您可以使用Unix locate 命令来找到文件。

  $ locate fintrf.h 
/ Applications / Matlab R2014a.app/extern/include/fintrf.h

fengdemo.F 的目录中,我们可以然后使用 -I 选项传递正确的目录

  -I ../../include/ 

然而,这会产生链接错误,因为我们没有指定位置可以找到 fintrf.h 的库。我们可以用 -L 选项来做到这一点(你需要用正确的选项替换 maci64 - Linux不能记住它,但你应该能够在 bin 目录中看到它)

  -L ../../../ bin / maci64 / 

现在我们需要告诉它使用 -leng -lmx 的库,所以完成的命令是

  $ ifort fengdemo.F -I ../../ include / -L ../../../ bin / maci64 / -leng -lmx 

并且它应该能够正确编译。



但还没有完成,因为它不会执行。我们需要正确设置我们的 PATH DYLD_LIBRARY_PATH 环境变量。具体而言,我们需要将MATLAB安装的 bin bin / maci64 目录添加到 PATH

  $ export PATH = $ PATH:/ Applications / Matlab\ R2014a.app/bin/ maci64:/ Applications / Matlab \ R2014a.app/bin 

bin / maci64 / sys / os / maci64 / DYLD_LIBRARY_PATH

  $ export DYLD_LIBRARY_PATH = $ DYLD_LIBRARY_PATH:/ Applications / Matlab\ R2014a.app/bin/maci64/:/Applications/Matlab\R2014a。 app / sys / os / maci64 / 

注意: c $ c> DYLD_LIBRARY_PATH 应该是 LD_LIBRARY_PATH 。感谢 Vladimir F 纠正我。



现在您可以使用

  $ ./a.out 

I am trying to integrate a Matlab program I wrote into some Fortran code. I tried to follow the example Mathworks provides. But I can't get it to compile because I can't find the header files it requests.

Does anyone know of an example of someone getting it to work on Linux using an Intel compiler. I think that might be part of the problem because Matlab only supports GNU Fortran on Linux.

And I realize this is a simple question, I just don't understand how to do anything in compiling more complicated than including multiple files with defined paths.

解决方案

Disclaimer: I'm currently using OS X so I can only provide output from OS X but everything should transfer easily over to Linux due to the Unix base. I also don't have the Intel Fortran compiler on OS X (only the C/C++ compiler).


Note: You will need to substitute the paths I use for the correct paths on your system depending on your MATLAB installation directory.


This issue isn't specific to the Intel Compiler, I also receive errors with the GCC Fortran compiler.

$ gfortran fengdemo.F 
fengdemo.F:1:0:

 #include "fintrf.h"
 ^
Fatal Error: fintrf.h: No such file or directory
compilation terminated.

You can use the Unix locate command to find files.

$ locate fintrf.h
/Applications/Matlab R2014a.app/extern/include/fintrf.h

In the directory where fengdemo.F is we can then pass the correct directory in using the -I option

-I../../include/

However, this produces linking errors as we haven't specified where the libraries for fintrf.h can be found. We can do this with the -L option (you will need to replace maci64 with the correct option for Linux - I can't remember it off the top of my head but you should be able to see it in the bin directory)

-L../../../bin/maci64/

Now we need to tell it what libraries to use with -leng -lmx and so the completed command is

$ ifort fengdemo.F -I../../include/ -L../../../bin/maci64/ -leng -lmx

and it should compile correctly.

We aren't finished yet though as it won't execute. We need to set up our PATH and DYLD_LIBRARY_PATH environment variables correctly. Specifically we need to add the bin and bin/maci64 directories of our MATLAB installation to PATH

$ export PATH=$PATH:/Applications/Matlab\ R2014a.app/bin/maci64:/Applications/Matlab\ R2014a.app/bin

and the bin/maci64/ and sys/os/maci64/ to DYLD_LIBRARY_PATH

$ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Applications/Matlab\ R2014a.app/bin/maci64/:/Applications/Matlab\ R2014a.app/sys/os/maci64/

Note: On Linux DYLD_LIBRARY_PATH should be LD_LIBRARY_PATH. Thanks to Vladimir F for correcting me.

Now you can execute the program using

$ ./a.out

这篇关于从英特尔Fortran调用Matlab(Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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