error #5149: Illegal character in statement label field with matlab2016b
Afficher commentaires plus anciens
I am trying to compile a fortran mex file which is associated with a matlab code. I ran the command ‘mex FileName.f90’ on Matlab 16b and it gave me the “error #5149: Illegal character in statement label field”. I am using Matlab 16b and Intel Parallel Studio XE 2016 for Fortran with Microsoft Visual Studio 2013. I tried to remove the /fixed from mexopts folder as suggested by several posts but still get the same error. Can someone help me to solve the issue? I am quite new to programming. Thank you Prasanna
Réponses (1)
sanidhyak
le 11 Mai 2025
I understand that you are encountering a “Fortran compiler error” while attempting to compile a “.f90” MEX file in MATLAB R2016b using “Intel Parallel Studio XE 2016” and “Microsoft Visual Studio 2013”. This issue commonly arises when the Intel Fortran compiler interprets “.f90” files as fixed-form Fortran, which expects “strict” formatting rules, even though “.f90” files typically use “free-form” syntax.
To resolve this, you will need to explicitly instruct the compiler to use “free-form” syntax by passing the “-free” flag. Kindly refer to the following command that can be executed directly in MATLAB:
mex('-v', 'FileName.f90', 'FCFLAGS=$FCFLAGS -free')
This ensures that the “.f90” file is compiled correctly using modern Fortran formatting.
Alternatively, you can create or modify a “mexopts” configuration file by running “mex -setup FORTRAN” and editing the relevant line in the generated “.bat” file from:
set FCFLAGS=/c /nologo /MD
to:
set FCFLAGS=/c /nologo /MD /free
This change will apply the “/free” flag every time you compile a Fortran MEX file, avoiding the error going forward.
For more details, you may refer to the following official documentations below:
- MATLAB MEX Command: https://www.mathworks.com/help/matlab/ref/mex.html
- Configure Fortran Compiler (“mex -setup”): https://www.mathworks.com/help/matlab/build-fortran-mex-files-1.html
- Intel Fortran Compiler Options Reference: https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2025-0/compiler-options-001.html
- Intel Fortran Source Form (Free vs Fixed): https://www.cita.utoronto.ca/~merz/intel_f10b/main_for/mergedProjects/lref_for/source_files/pgbsourc.htm
I hope this helps!
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!