If I tell the C preprocessor to #include a file and use CPPFLAGS to help find the needed file, then the file is included already, right? What, if any, use is telling the C compiler about the same include directory with CFLAGS?
+2
A:
I don't think there is any use.
The implicit make rules indicates that CFLAGS
is only used when compiling C programs (from .c to .o). The value of CPPFLAGS
is also added to the compiler command line.
CPPFLAGS
is also used in the following rules:
- Compiling C++ programs
- Compiling Fortran and Ratfor programs
- Preprocessing Fortran and Ratfor programs
- Assembling and preprocessing assembler programs
- Making Lint Libraries from C, Yacc, or Lex programs
Since CPPFLAGS
is used in every case where CFLAGS
is used, there seems to be no point in adding -I
directives to CFLAGS
that are already in CPPFLAGS
.
Of course, if your Makefile has custom rules that pass CFLAGS
to the compiler, but omit CPPFLAGS
, it's a different story.
Thomas
2010-05-03 06:51:52
Order could be though make a difference but at least for GNU make default rules, CLFAGS is added after CPPFLAGS and so you can't use it to change the relative order of two directories (note that if you depend on that, you already are in a tigh situation).
AProgrammer
2010-05-03 09:12:25
Thank you for the help. I guess what I'm left wondering is what the C compiler does with include paths itself. Say, for the moment, that the compiler does **NOT** see CPPFLAGS. In that case, would it barf without knowing the needed include path? Why? As far as I see, the preprocessor has already resolved the path and included the needed include file.
Sunny209
2010-05-03 19:34:27
Yeah, but most of the time, the `cc` program does both preprocessing *and* compiling. There's no separate program for either.
Thomas
2010-05-03 20:19:20
Oh, I see. THANKS!!!!!
Sunny209
2010-05-03 20:22:12