Difference between CPPFLAGS and CXXFLAGS in GNU Make

MakefileGnu Make

Makefile Problem Overview


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

Makefile Solutions


Solution 1 - Makefile

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

Solution 2 - Makefile

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

Solution 3 - Makefile

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

See https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html">here</a>;.

Solution 4 - Makefile

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionelasticratView Question on Stackoverflow
Solution 1 - MakefileKieronView Answer on Stackoverflow
Solution 2 - MakefileChristophView Answer on Stackoverflow
Solution 3 - MakefilestarblueView Answer on Stackoverflow
Solution 4 - MakefileJames MooreView Answer on Stackoverflow