156

What's the difference between CPPFLAGS and CXXFLAGS in GNU Make?

mrflash818
  • 930
  • 13
  • 24
elasticrat
  • 7,060
  • 5
  • 36
  • 36

4 Answers4

237

CPPFLAGS is supposed to be for flags for the C PreProcessor; CXXFLAGS is for flags for the C++ compiler.

The default rules in make (on my machine, at any rate) pass CPPFLAGS to just about everything, CFLAGS is only passed when compiling and linking C, and CXXFLAGS is only passed when compiling and linking C++.

Ergwun
  • 12,579
  • 7
  • 56
  • 83
Kieron
  • 11,588
  • 5
  • 34
  • 29
35

By default, CPPFLAGS will be given to the C preprocessor, while CXXFLAGS will be given to the C++ compiler.

The GNU Make Manual is a good resource for questions like this (see Implicit Variables).

Matthew
  • 28,056
  • 26
  • 104
  • 170
Christoph
  • 164,997
  • 36
  • 182
  • 240
  • 31
    I was staring right at the manual when I had this exact same question. I typed CPPFLAGS into stackoverflow and got the answer much quicker than searching the manual. – Dan Hook Aug 11 '09 at 18:00
19

CPPFLAGS are for the C preprocessor, while CXXFLAGS are for the C++ compiler.

See here.

starblue
  • 55,348
  • 14
  • 97
  • 151
0

By default, they're set to something.

In practice, you need to know what every single project does. Virtually no one uses those defaults built into make, and if you rely on, for example, CPPFLAGS meaning "flags to the C preprocessor" you'll find that the project you care about has used it to mean "flags to the C++ compiler" instead. And does the CFLAGS flag get passed to C++ compile lines? Sometimes. Not always. Etc, etc, etc.

James Moore
  • 8,636
  • 5
  • 71
  • 90
  • 1
    Some projects use CPPFLAGS to mean "c++ flags", but those projects are almost definitely doing so out of ignorance of the standard, and it would be better if they used CXXFLAGS. – Score_Under Aug 08 '18 at 09:22
  • @Score_Under I don't disagree with you, but the world is filled with projects that couldn't care less what anyone thinks the standard is. You _always_ have to investigate. – James Moore Aug 09 '18 at 14:12