简体   繁体   中英

Get preprocessor output from C through MATLAB mex

I want to get the preprocessor output when compiling my c-code through mex of MATLAB using MinGW64 Compiler (C) so using gcc (right?). From this post I got that you can do this with pure gcc passing the option -E to gcc. However I installed gcc through MATLAB app and therefore cannot access it through command line (would also appreciate a command how to do that, without reinstalling MinGW64 and setting it up manually for use with MATLAB).

I tried to do the following assuming that compiler flags are the right way to pass the argument:

mex -c grampc_run.c -I../../include -I../include COMPFLAGS='$COMPFLAGS -E'

This just results in the creation of the object file.

COMPFLAGS is used by the MSCV compiler. The GCC compiler loos at CFLAGS and CXXFLAGS (for C and C++ compilation, respectively). See here . Thus, you should use the following syntax:

mex -c grampc_run.c -I../../include -I../include CFLAGS='$CFLAGS -E'

You might also want to add the -v option to mex . GCC puts the preprocessor output to the standard output, which mex might not show you. With -v it does show you all the output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM