C++ comments in Mex files under Linux
Show older comments
For many years users support problems about compiling C-sources containing C++ comments under Linux, because the automatically created mexopts file enables the -ansi style instead of the modern std=-c99 style for the GCC compiler.
Other compilers accept the C++ comments for a long time: LCC (shipped with Matlab or downloaded from the net), Borland BCC, OpenWatcom, MSVC, Intel ICC, Tiny C (TCC), PCC, ...
Is there any reason not to enable the 12 year old C99 standard in the default mexopts file for the GCC under Linux?
BTW: To solve the problem, you can edit the mexopts file: replace '-ansi' by '-std=c99' or add these flags to the MEX call:
mex -O CFLAGS="\$CFLAGS -std=c99" yourfile.c
1 Comment
Matt
on 3 Apr 2013
Edited: Walter Roberson
on 4 Apr 2013
I have a follow-up question... I am using Simulink s-functions that have C++ style comments. I have changed the CFLAGS option in the mexopts file and can mex the S-functions no problem. However, when I run the model in rapid accelerator mode, it appears to recompile the s-functions and uses -ansi instead of -std=c99.
Is there a recommended way to address this problem? I have found a solution, but it involves manually changing the MODEL.mk file in the slprj folder or actually changing the default raccel tmf file, both of which seem sketchy to me.
EDIT: More info... I traced it back to unixtools.mk, which changes the CFLAGS based on the value of TGT_FCN_LIB in the makefile. Apparently, TGT_FCN_LIB takes the value of ANSI_C, ISO_C, or GNU and the CFLAGS change accordingly. TGT_FCN_LIB is set in the MODEL.mk makefile, but I am not sure what parameter in the model's configuration parameters determines its value (if any). I manually changed it to ISO_C in MODEL.mk and everything compiles fine.
EDIT 2: I have reposted this as a new question ( http://www.mathworks.com/matlabcentral/answers/69768-c-style-comments-in-s-functions-with-linux)
Accepted Answer
More Answers (0)
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!