Discussion:
How to let autoconf NOT include ($CFLAGS) in LINK?
a***@ourserver.demon.nl
2005-07-21 07:29:51 UTC
Permalink
Sorry if this is a question already answered, but I couldn't find this on
google, this list and the manual, searching for "LINK (without) ($CFLAGS)"

The fact is that after running autoconf and automake, the makefile tries to link
while also putting $CFLAGS on the command line. I checked that the ($CFLAGS)
directive was also present in Makefile.in, so I guess that rules out an
automake issue then. I, however, do not know whether this is a libtool or
autoconf issue.

Now, gcc handles compiler flags on the command line well when linking, but 'ld'
on a Tru64 machine doesn't :-)

So my question is, is there a simple way to only include ($CFLAGS) when
compiling, and only ($LDFLAGS) when linking, NOT ($CFLAGS)?

For the record, the (I hope) relevant lines in configure.in are:

Oh, and by the way, I tried setting LDFLAGS to "" using AC_SUBST, but that
didn't help either :-)

[ QUOTE configure.in ]

AM_DISABLE_SHARED

# Checks for programs
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_AWK
AC_PROG_LIBTOOL

# Checks for header files.
{ SNIP }

# Checks for typedefs, structures, and compiler characteristics.
{ SNIP }

# Checks for library functions.
{ SNIP }

#create include variable

#create compiler options
AC_SUBST(CFLAGS, "-g -O -Wall -ansi")

[ /QUOTE ]

and my Makefile.am:

[ QUOTE Makefile.am ]

bin_PROGRAMS = synop_zzz

synop_zzz_SOURCES = synop_zzz.c
synop_zzz_LDADD = @top_srcdir@/generic/libgeneric.la
@top_srcdir@/bufr_parser/libbufr_parser.la
@top_srcdir@/conversions/libconversions.la

INCLUDES = -***@top_srcdir@/generic -***@top_srcdir@/bufr_parser
-***@top_srcdir@/conversions

[ /QUOTE ]
Andre Caldas
2005-07-21 09:16:42 UTC
Permalink
Hello!
Post by a***@ourserver.demon.nl
AC_SUBST(CFLAGS, "-g -O -Wall -ansi")
Sorry, I don't really know about your problem, but the FLAGS you want
to impose on your users are their choice, not yours.

Andre Caldas.
Andreas Schwab
2005-07-21 09:02:26 UTC
Permalink
Post by a***@ourserver.demon.nl
Now, gcc handles compiler flags on the command line well when linking, but 'ld'
on a Tru64 machine doesn't :-)
Automake generates these variable settings:

CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@

Thus there is nothing that calls 'ld' with $(CFLAGS), only $(CC). In
fact, if you are using gcc then calling the linker directly is almost
always wrong.

Andreas.
--
Andreas Schwab, SuSE Labs, ***@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Stepan Kasal
2005-07-21 09:33:39 UTC
Permalink
Hello,
Post by a***@ourserver.demon.nl
I checked that the ($CFLAGS)
directive was also present in Makefile.in, so I guess that rules out an
automake issue then.
no, that was Automake who wrote Makefile.in. So yes, all issues we discuss in
this thread are automake issues.
Post by a***@ourserver.demon.nl
AC_SUBST(CFLAGS, "-g -O -Wall -ansi")
It was already said that you shouldn't use AC_SUBST([CFLAGS]) nor
AC_SUBST([LDFLAGS]); this is explained in the Automake manual.
All AC_SUBST variables are also available as make variables, so you
can use
synop_zzz_LDADD = $(top_srcdir)/generic/libgeneric.la

And it's actually considered better style.

Have a niec day,
Stepan
Ralf Corsepius
2005-07-21 09:26:30 UTC
Permalink
Post by a***@ourserver.demon.nl
So my question is, is there a simple way to only include ($CFLAGS) when
compiling, and only ($LDFLAGS) when linking, NOT ($CFLAGS)?
Firstly, this is OT for this list. It's an automake question.

To answer your question: no.

Automake rules assume you using the compiler to link and not to use ld
directly. That's why automake uses CCLD (calling the linker through CC)
and not LD (the raw linker) in "LINK".

It does so, because CFLAGS can implicitly influence linking in various
ways, which should remain transparent to users.
Post by a***@ourserver.demon.nl
#create compiler options
AC_SUBST(CFLAGS, "-g -O -Wall -ansi")
BTW: Such constructs should be considered as bad design.

1. CFLAGS is supposed to be overridden from the command line and not to
be hard coded into configure.acs.
2. This is non portable. You are hard-coding GCC specific flags into
your package.
3. CFLAGS already are implicitly AC_SUBST'ed

Ralf
a***@ourserver.demon.nl
2005-07-21 09:59:46 UTC
Permalink
Post by Ralf Corsepius
Post by a***@ourserver.demon.nl
So my question is, is there a simple way to only include ($CFLAGS) when
compiling, and only ($LDFLAGS) when linking, NOT ($CFLAGS)?
Firstly, this is OT for this list. It's an automake question.
To answer your question: no.
Automake rules assume you using the compiler to link and not to use ld
directly. That's why automake uses CCLD (calling the linker through CC)
and not LD (the raw linker) in "LINK".
It does so, because CFLAGS can implicitly influence linking in various
ways, which should remain transparent to users.
Post by a***@ourserver.demon.nl
#create compiler options
AC_SUBST(CFLAGS, "-g -O -Wall -ansi")
BTW: Such constructs should be considered as bad design.
1. CFLAGS is supposed to be overridden from the command line and not to
be hard coded into configure.acs.
2. This is non portable. You are hard-coding GCC specific flags into
your package.
3. CFLAGS already are implicitly AC_SUBST'ed
Ralf
For future reference (like people searching this list), I followed the helpful
comments from these three people and did the following:

* I removed the AC_SUBST(CFLAGS, "-g -O -Wall -ansi") directive
* I added the Tru64 specific flags in a script that calls ./configure with the
appropriate CFLAGS="-foo -bar" settings.

That works like a charm. On CygWin I of course use other CFLAGS.

Thanks again for all your (I might say QUICK) help! Now I can proceed making
_actual_ software :-)

Jeroen
Vania Joloboff
2013-03-01 08:25:55 UTC
Permalink
We have exactly the same problem

We want to compile code with CFLAGS = -march=armv5t -mthumb
-mthumb-interwork

but we do not want to link with these options because they actually produce
a different executable that we do not want

We want to have only AM_LDFLAGS and LDFLAGS when linking, not CFLAGS

What do we do ?
--vj



--
View this message in context: http://gnu-autoconf.7623.n7.nabble.com/How-to-let-autoconf-NOT-include-CFLAGS-in-LINK-tp6155p18566.html
Sent from the Gnu - Autoconf - General mailing list archive at Nabble.com.
Ralf Corsepius
2013-03-01 18:20:16 UTC
Permalink
Post by Vania Joloboff
We have exactly the same problem
We want to compile code with CFLAGS = -march=armv5t -mthumb
-mthumb-interwork
but we do not want to link with these options because they actually produce
a different executable that we do not want
We want to have only AM_LDFLAGS and LDFLAGS when linking, not CFLAGS
This means, your toolchain is broken or your CFLAGS are wrong.
Post by Vania Joloboff
What do we do ?
Likely something CFLAGS=-Wl,<whatever> or similar could work.

Ralf

Loading...