Errors in linking fortran code that imports a MAT-file [duplicate]

烂漫一生 提交于 2019-12-08 07:28:28

For lower case file extensions *.f90 or *.f the pre-processor is typically deactivated. To enable that, either rename the (main) file to have a capital extension *.F90 or *.F, or provide the corresponding command-line option (-cpp for gfortran, -fpp for ifort).

Assuming the missing subroutines/functions are actually declared in fintrf.h, this should solve your problem.

You should additionally tell the compiler to link against the libraries containing the Matlab functions.

WYSIWYG

As pointed out by Alexander Vogt, the compiler requires -cpp option for the pre-processor to recognize the header file and not to treat it as illegal.

Linking requires finitrf.h which is usually located in the <matlabroot>/extern/include and the essential libraries are present in <matlabroot>/bin/<arch>/.

But just specifying this does not work and specification of the exact matlab library seems essential; these are libmat.so and libmx.so.

These libraries are in turn dependent on other libraries so another flag is required to set the rpath.

Finally it works with following command:

gfortran main.f90 dmotifs.o param.o ssa.o -I/usr/local/matlab2008a/extern/include -L/usr/local/matlab2008a/bin/glnxa64 -cpp -o main -lmat -lmx -Wl,-rpath /usr/local/matlab2008a/bin/glnxa64/

or in general

gfortran program.f90 -I<matlabroot>/extern/include -L<matlabroot>/bin/<arch> -cpp -lmat -lmx -Wl, -rpath <matlabroot>/bin/<arch> -o program.out

Also see this post that is about the same problem in C.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!