Discussion:
How can I override CXXFLAGS?
bholland
2014-08-10 17:48:49 UTC
Permalink
Hi everyone,

I am working on a project that I joined and I noticed that the flags are all
a mess. When a flag called --enabled-debug was set it it sets

AM_CXXFLAGS="$AM_CXXFLAGS -g -Wall -O0"
AM_LDFLAGS="$AM_LDFLAGS -g"

but when I compile all of my stuff, the CXXFLAGS variable is set to -g -O2
which completely negates the ability to debug. Likewise, I want to set
LDFLAGS to actually link the compiled libraries first as oppose to anything
that I have installed. I don't think this is a problem as LDFLAGS apparently
doesn't have a default for autoconf, or at least not one that overrides.

I am actually surprised that autoconf decided that the default CXXFLAG set
was not empty. I am sure there are reasons for that, but to me it causes
more harm than good. I set AM_CXXFLAGS with the expectation that if I don't
explicitly set CXXFLAGS, that I get to use whatever I set for AM_CXXFLAGS
but that is not the case. Even in build mode

AM_CXXFLAGS="$AM_CXXFLAGS -O3"

will be overridden to be -g -O2 by CXXFLAGS.

Basically, what I want is the expected default behavior. I want to set
CXXFLAGS to nothing by default unless it has been specified by the user. It
is very strange that this is not how it works so I suppose I am also curious
as to why this is the case.

Thanks,
~Ben



--
View this message in context: http://gnu-autoconf.7623.n7.nabble.com/How-can-I-override-CXXFLAGS-tp19630.html
Sent from the Gnu - Autoconf - General mailing list archive at Nabble.com.
Bob Friesenhahn
2014-08-10 20:38:07 UTC
Permalink
I strongly recommend that you go back and read the Autoconf and
Automake documentation. It does seem like the project that you joined
does have some issues.

Autoconf and automake work in conjunction with each other and can
accomplish what you desire if used correctly.

It is true that Autoconf does produce a default set of CXXFLAGS but
these can be easily overridden by the user, unless the project was
constructed incorrectly.

Bob
--
Bob Friesenhahn
***@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
Nick Bowler
2014-08-10 21:21:55 UTC
Permalink
Post by bholland
I am working on a project that I joined and I noticed that the flags are all
a mess. When a flag called --enabled-debug was set it it sets
AM_CXXFLAGS="$AM_CXXFLAGS -g -Wall -O0"
AM_LDFLAGS="$AM_LDFLAGS -g"
but when I compile all of my stuff, the CXXFLAGS variable is set to -g -O2
which completely negates the ability to debug.
[...]
Post by bholland
Basically, what I want is the expected default behavior. I want to set
CXXFLAGS to nothing by default unless it has been specified by the user. It
is very strange that this is not how it works so I suppose I am also curious
as to why this is the case.
Your observation is correct, Autoconf sets default values
for CFLAGS/etc. if they are not explicitly specified by the
user. This is by design: if it did not happen, the sequence
./configure && make && make install would produce an unoptimized
build, which is not really good user experience.

Usually it suffices to just set debugging flags directly on the
command line, e.g.,

./configure CXXFLAGS="-g"

which has the side effect of suppressing the default flag assignment.
If for some reason you want to change the defaults, you can just set
them before AC_PROG_CXX, taking care not to override the user. For
example:

AS_IF([$debug_enabled && test x"${CXXFLAGS+set}" != x"set"],
[CXXFLAGS=-g])

Cheers,
--
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)
Loading...