0

I want the preprocessed output of a .c file, but I also want to include a header file without the macro "include..." in the .c file. Usually, you add the -I option for including a directory where headers are. But if I want to combine -I and -E, gcc does't seem to include my header files in the specified directory. My command:

gcc -E -I/externDefines myFirmware.c > myFirmware.preprocessed

Does anyone know what the problem could be?

2
  • 1
    You're probably looking for the -include <path> flag. Commented Aug 13, 2021 at 11:49
  • 1
    " but I also want to include a header file without the macro "include..."" It's not a macro, it's an include. And the correct way to include files in C. If you don't want to use it for whatever reason (building a unit test etc) then consider wrapping the file you are testing inside another file that contains the relevant include. Commented Aug 13, 2021 at 11:52

1 Answer 1

1

-I does not mean “Include the header files from the given directory in the compilation.” It means “When searching for a file requested with #include, look for the file in the given directory.”

GCC has a command-line switch, -include file that will include a file in the compilation. However, it includes a single file, so you must list each file you want included; it will not automatically include all header files in a single directory. The command-line shell you are using may have features that help generate a list of -include switches with the file names.

A portable way to include a header file X.h while compiling Y.c without changing Y.c would be to create an auxiliary file containing:

#include "X.h"
#include "Y.c"

and then compile that instead of Y.c.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.