Difference between CPPFLAGS and CXXFLAGS in GNU Make
Asked Answered
S

4

158

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

Sideburns answered 30/1, 2009 at 14:10 Comment(1)
You can get make to print out its predefined variables and rules database using the invocation make -pTuba
P
239

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++.

Peag answered 30/1, 2009 at 14:23 Comment(7)
it seems like a common practice that CFLAGS would also be passed when compile C++?Milieu
Ha. 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.Indefinable
@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.Verbiage
CPPFLAGS is NOT for C Plus Plus but CXXFLAGS is.Jubilation
True but terrible. This feels like we are stuck in the 80s.Saprogenic
So damn confusing. At first I thought CXX meant "both C++ and C."Maiolica
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.Authorize
V
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).

Vitrescence answered 30/1, 2009 at 14:16 Comment(1)
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.Diphosgene
S
19

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

See here.

Sectionalize answered 30/1, 2009 at 14:17 Comment(0)
V
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.

Verbiage answered 28/9, 2017 at 21:27 Comment(2)
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.Philia
@Philia 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.Verbiage

© 2022 - 2024 — McMap. All rights reserved.