0

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.

hcl734
  • 372
  • 1
  • 10
  • Just a side node: I can do this using Visual Studio Developer Command Prompt with: cl my_file.c /P /I"C:\...\include" /I"C:\Program Files\MATLAB\R2018b\extern\include" /out:my_file.i --> \P is the right flag in VS – hcl734 Jun 21 '19 at 09:41

1 Answers1

1

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.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120