Mex fortran code on Matlab R2013a, Linux 64: Illegal preprocessor directive
6 views (last 30 days)
Show older comments
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!
0 Comments
Answers (2)
James Tursa
on 28 Feb 2017
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 Comment
Ren Zetian
on 10 Mar 2017
8 Comments
Walter Roberson
on 14 Mar 2017
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
See Also
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!