Mex fortran code on Matlab R2013a, Linux 64: Illegal preprocessor directive
이전 댓글 표시
Hello,
I am using Matlab R2013a on Linux 64 platform, trying to mex fortran code. The gcc version is gcc-4.4.7.
[zhumin@ln1 ~]$ echo $PATH
/apps/lib/gcc-4.4.7-install/bin:/apps/lib/gcc-4.7.1/bin:/apps/intel/impi/4.0.2.003/intel64/bin:/apps/intel/Compiler/11.1/069/f/bin/intel64:/apps/intel/Compiler/11.1/069/c/bin/intel64:/apps/intel/Compiler/11.1/069/f/bin/intel64:/apps/intel/Compiler/11.1/069/c/bin/intel64:/apps/intel/impi/4.0.2.003/intel64/bin:/jobmgr/lsf8.0/8.0/linux2.6-glibc2.3-x86_64/etc:/jobmgr/lsf8.0/8.0/linux2.6-glibc2.3-x86_64/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/zhumin/bin
[zhumin@ln1 ~]$ echo $LD_LIBRARY_PATH
/apps/lib/gcc-4.4.7-install/lib64:/apps/lib/gcc-4.8.4/gcc-4.8.4/contrib/mpfr-2.4.2/lib:/apps/lib/gcc-4.8.4/gcc-4.8.4/contrib/gmp-4.3.2/lib:/apps/lib/gcc-4.8.4/gcc-4.8.4/contrib/mpc-0.8.1/lib:/apps/lib/gcc-4.7.1/lib64:/apps/intel/impi/4.0.2.003/intel64/lib:/apps/intel/Compiler/11.1/069/f/lib/intel64:/apps/intel/Compiler/11.1/069/f/mkl/lib/em64t:/apps/intel/Compiler/11.1/069/c/lib/intel64:/apps/intel/Compiler/11.1/069/c/ipp/em64t/sharedlib:/apps/intel/Compiler/11.1/069/c/mkl/lib/em64t:/apps/intel/Compiler/11.1/069/c/tbb/intel64/cc4.1.0_libc2.4_kernel2.6.16.21/lib:/usr/lib64:/usr/lib:/apps/intel/Compiler/11.1/069/f/lib/intel64:/apps/intel/Compiler/11.1/069/f/mkl/lib/em64t:/apps/intel/Compiler/11.1/069/c/lib/intel64:/apps/intel/Compiler/11.1/069/c/ipp/em64t/sharedlib:/apps/intel/Compiler/11.1/069/c/mkl/lib/em64t:/apps/intel/Compiler/11.1/069/c/tbb/intel64/cc4.1.0_libc2.4_kernel2.6.16.21/lib:/apps/intel/impi/4.0.2.003/intel64/lib:/jobmgr/lsf8.0/8.0/linux2.6-glibc2.3-x86_64/lib
Then when I mex the fortran file calculateG.f in Matlab, it errors "Illegal preprocessor directive".
>> mex -setup
Options files control which compiler to use, the compiler and link command
options, and the runtime libraries to link against.
Using the 'mex -setup' command selects an options file that is
placed in /home/zhumin/.matlab/R2013a and used by default for 'mex'. An options
file in the current working directory or specified on the command line
overrides the default options file in /home/zhumin/.matlab/R2013a.
To override the default options file, use the 'mex -f' command
(see 'mex -help' for more information).
The options files available for mex are:
1: /apps/soft/MATLAB/R2013a/bin/mexopts.sh :
Template Options file for building MEX-files
0: Exit with no changes
Enter the number of the compiler (0-1):
1
Overwrite /home/zhumin/.matlab/R2013a/mexopts.sh ([y]/n)?
y
/apps/soft/MATLAB/R2013a/bin/mexopts.sh is being copied to
/home/zhumin/.matlab/R2013a/mexopts.sh
**************************************************************************
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
Building with the -largeArrayDims option enables the new API.
**************************************************************************
>> mex calculateG.f
Warning: calculateG.f:1: Illegal preprocessor directive
calculateG.f:10.6:
mwPointer plhs(*), prhs(*)
1
Error: Unclassifiable statement at (1)
......
How to solve this problem, please? Thanks!
답변 (2개)
James Tursa
2017년 2월 28일
The warning indicates that something went wrong with the pre-processor. The error indicates that mwPointer is not defined. What is supposed to happen is you include this file at the front of your Fortran source code:
#include "fintrf.h"
And then that file contains the pre-processor directives that get mwPointer defined. For some reason, this didn't happen properly. Can you try mexing with the -v option to maybe get more information on the problems that are occurring?
댓글 수: 1
Ren Zetian
2017년 3월 1일
편집: Ren Zetian
2017년 3월 13일
Ren Zetian
2017년 3월 10일
0 개 추천
댓글 수: 8
Walter Roberson
2017년 3월 10일
The code you posted does not agree with the line numbers of the error messages. Either you trimmed some comments in posting, or else the line numbers are after expansion of the include and the invalid preprocessor directive is inside the file included. Or both.
Ren Zetian
2017년 3월 13일
Walter Roberson
2017년 3월 13일
When I look at https://gcc.gnu.org/onlinedocs/gfortran/Preprocessing-Options.html I notice that ".f" is not on the list of extensions for which -cpp is automatically enabled. I see ".F" on the list, but the list is case-sensitive since it specifically lists .fpp as distinct from .FPP
Ren Zetian
2017년 3월 14일
Walter Roberson
2017년 3월 14일
I find suggestion that it might be called libgfortranbegin . Or it might just need a -L mex option to point it to the right directory.
I also find reference to
apt-get install gfortran-multilib
Ren Zetian
2017년 3월 14일
Ren Zetian
2017년 3월 14일
Walter Roberson
2017년 3월 14일
Possibly you need to install gfortran to get the library, but I am not sure. You appear to have passed the compile stage; the error now is in the link stage. You should locate either lgfortran or libgfortran and add -L to point to the right directory and -l to point to the right library name
카테고리
도움말 센터 및 File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!