What's the difference between CPPFLAGS and CXXFLAGS in GNU Make?
-
3You can get make to print out its predefined variables and rules database using the invocation `make -p` – Daniele Pallastrelli Jul 02 '14 at 07:57
4 Answers
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++.
-
1it seems like a common practice that CFLAGS would also be passed when compile C++? – Baiyan Huang May 12 '13 at 13:12
-
31Ha. I get it! the `x` is a `+` turned on it's side because `C++FLAGS` would blow up the compiler. ... I may have arrived to the party late, but that's still better than arriving on time to the wrong party. – Jacksonkr Mar 10 '16 at 15:18
-
@BaiyanHuang I wouldn't think about it as common or not; you'll run into both conventions. You have to know what your current setup is doing. – James Moore Nov 16 '16 at 23:29
-
3
-
-
So damn confusing. At first I thought `CXX` meant "both C++ and C." – Константин Ван Jun 26 '21 at 12:07
-
The confusion may stem from the fact that the suffix for C++ source files is often `.cpp`, as in `mycode.cpp`. I have actually also seen source files with the `.cxx` suffix. – stackoverflowuser2010 Sep 19 '21 at 00:13
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).
-
31I 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
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.

- 8,636
- 5
- 71
- 90
-
1Some 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