This is the mail archive of the
mailing list for the GCC project.
Re: What options should be set in Make variables CFLAGS, CXXFLAGS, CPPFLAGS and LDFLAGS?
- From: Peng Yu <pengyu dot ut at gmail dot com>
- To: Paul Smith <psmith at gnu dot org>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 24 Jan 2019 12:46:47 -0600
- Subject: Re: What options should be set in Make variables CFLAGS, CXXFLAGS, CPPFLAGS and LDFLAGS?
- References: <CABrM6wk33tv5HVaUOWYMy7ssAQD0CdLsdTX0=RnScHiJa-Yfirstname.lastname@example.org> <email@example.com> <CABrM6wmceyre-7oe7+R8oK-yYaSSh4gQH8=c3nuRYK+dXoOUEg@mail.gmail.com> <firstname.lastname@example.org>
On Thu, Jan 24, 2019 at 12:31 PM Paul Smith <email@example.com> wrote:
> On Thu, 2019-01-24 at 12:10 -0600, Peng Yu wrote:
> > So only the following in the gcc manual go to CPPFLAGS. All other
> > options go to other GNU Make variables.
> > Preprocessor Options
> > -Aquestion=answer -A-question[=answer] -C -dD -dI -dM -dN
> > -Dmacro[=defn] -E -H -idirafter dir -include file -imacros file
> > -iprefix file -iwithprefix dir -iwithprefixbefore dir -isystem
> > dir -imultilib dir -isysroot dir -M -MM -MF -MG -MP -MQ -MT
> > -nostdinc -P -fdebug-cpp -ftrack-macro-expansion
> > -fworking-directory -remap -trigraphs -undef -Umacro -Wp,option
> > -Xpreprocessor option -no-integrated-cpp
> I don't think you can really make that statement: it depends on your
> As I said, one idea behind using a separate variable is that there may
> be other tools that you want to use which also take preprocessor
> arguments. It's not uncommon (or at least was not in the past) for
> other tools to use the preprocessor to process source code for other
> reasons than compilation; those other tools would need the -I and -D
> options (and -U although that's rarely used). However, most of the
> less standard flags above will not be recognized by most of these other
> tools and could cause them to throw errors.
> There's no one-size-fits-all definition, IMO. The answer to all your
> questions is, "it depends on what you want to do". If you have no
> reason to ever use the preprocessor separately maybe you don't need a
> separate CPPFLAGS at all.
> There's just a general rule-of-thumb:
> * preprocessor options go into CPPFLAGS
> * options that can be used with BOTH C compilers and C linkers go into
> * options that can be used with BOTH C++ compilers and C++ linkers go
> into CXXFLAGS
> * options that can be used ONLY with linkers, but not compilers, go
> into LDFLAGS, except -l which goes into LDLIBS.
> Is there a particular reason you want to be so precise about this?
There is quite a confusion about how to use make variables. Different
sources give different bits of advice. I'd like to make it clear about