3

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
  • 3
    @Duracell: No, that's CXXFLAGS. CPPFLAGS is for the C PreProcessor. Commented May 3, 2010 at 6:53
  • @Thoams The clarification you made is important. There are numerous misleading references to CPPFLAGS vs. CXXFLAGS. Commented May 23, 2012 at 18:13

1 Answer 1

2

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.

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

4 Comments

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).
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.
Yeah, but most of the time, the cc program does both preprocessing and compiling. There's no separate program for either.
cpp is most certainly separate from cc. The confusion arises because it is rarely invoked directly as cc usually takes care of it. Think of cpp as a language templater, it does not understand nor care about the underlying source code generated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.