On Wed, Jan 24, 2018 at 6:55 PM, Zack Weinberg <za...@panix.com> wrote:
> On Wed, Jan 24, 2018 at 4:36 PM, Ferenc Wágner <wf...@niif.hu> wrote:
>> Hi,
>>
>> Since ceil() can be inlined when optimization is enabled, I use
>>
>> AC_SEARCH_LIBS([ceil], [m], , [AC_MSG_ERROR([ceil not found])])
>> AC_SUBST([m_LIBS], [$LIBS])
>>
>> to link against libm only when necessary (that is, when ceil is not
>> inlined).  However, it does not work because GCC says in config.log:
>>
>> conftest.c:76:6: warning: conflicting types for built-in function 'ceil'
>>  char ceil ();
>>       ~~~~
>>
>> and inlining is disabled, thus ceil becomes an undefined reference
>> without -lm.  However, in the actual code where math.h is #included, the
>> above warning does not happen, ceil is inlined and I unnecessarily link
>> with -lm.  How could I overcome this?
>
> You could try setting -Wl,--as-needed (which really should be the
> default) in your makefiles.

That was unnecessarily cryptic, sorry.

The GNU linker accepts an option --as-needed which will make it
actually check whether shared libraries (such as libm) satisfy any
undefined symbols before adding them to the executable's list of
needed shared libraries.  (This is not the default only for silly
historical reasons which let's not get into here.)  If you add that to
your link commands in your Makefiles, libm will get pulled in only if
it's actually necessary, which is better than trying to probe for
whether it will actually be necessary in the configure script, since
inlining is somewhat unpredictable.. The compiler driver doesn't know
about it, though, so you have to spell it -Wl,--as-needed on your
actual command lines.

If you are using Automake,  I believe you can just say

AM_LDFLAGS = -Wl,--as-needed

and get this applied to all of your executables.

zw

_______________________________________________
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf

Reply via email to