After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 697330 - Fails to build with the gold linker due to missing reference to libm
Fails to build with the gold linker due to missing reference to libm
Status: RESOLVED FIXED
Product: cogl
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Cogl maintainer(s)
Cogl maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-04-05 11:14 UTC by Emanuele Aina
Modified: 2013-04-23 17:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
build: Fix linking cogl-gles2-gears with gold by referencing libm (1.08 KB, patch)
2013-04-05 11:14 UTC, Emanuele Aina
none Details | Review
build: Use LT_LIB_M to find the math library in a portable way (2.06 KB, patch)
2013-04-05 11:15 UTC, Emanuele Aina
none Details | Review
build: Use LT_LIB_M to find the math library in a portable way (2.30 KB, patch)
2013-04-05 11:22 UTC, Emanuele Aina
none Details | Review
gitignore: Ignore the examples/cogl-gles2-gears executable (654 bytes, patch)
2013-04-05 11:23 UTC, Emanuele Aina
none Details | Review
Fix a warning about ‘sincos’ in examples/cogl-gles2-gears (2.13 KB, patch)
2013-04-05 17:11 UTC, Neil Roberts
none Details | Review

Description Emanuele Aina 2013-04-05 11:14:51 UTC
Since the GNU gold linker uses '--no-copy-dt-needed-entries'/'--no-add-needed'
by default, every reference to symbols coming from indireclty referenced
libraries will cause linking to fail:

make[2]: Entering directory `/home/em/dev/cogl/examples'
CCLD   cogl-gles2-gears
cogl-gles2-gears.c:183: error: undefined reference to 'sincos'
cogl-gles2-gears.c:184: error: undefined reference to 'sincos'
cogl-gles2-gears.c:185: error: undefined reference to 'sincos'
cogl-gles2-gears.c:186: error: undefined reference to 'sincos'
collect2: error: ld returned 1 exit status
make[2]: *** [cogl-gles2-gears] Error 1
Comment 1 Emanuele Aina 2013-04-05 11:14:54 UTC
Created attachment 240718 [details] [review]
build: Fix linking cogl-gles2-gears with gold by referencing libm

With the binutils-gold linker the '--no-copy-dt-needed-entries' flag is
active by default and using any symbol from indirectly loaded libraries
will result in undefined reference errors.
Comment 2 Emanuele Aina 2013-04-05 11:15:03 UTC
Created attachment 240719 [details] [review]
build: Use LT_LIB_M to find the math library in a portable way
Comment 3 Emanuele Aina 2013-04-05 11:22:59 UTC
Created attachment 240720 [details] [review]
build: Use LT_LIB_M to find the math library in a portable way

Also add the libtool-generated config.lt to the .gitignore patterns.
Comment 4 Emanuele Aina 2013-04-05 11:23:09 UTC
Created attachment 240721 [details] [review]
gitignore: Ignore the examples/cogl-gles2-gears executable
Comment 5 Neil Roberts 2013-04-05 16:54:37 UTC
Thanks for the patches. They look good to me but I just have a few comments.

It might be better to put the $(LIBM) in common_ldadd for the examples. Otherwise we're quite likely to forget that we need to add this and we will start using more math functions in other examples and it will break again. I don't think it will really matter if we add it to examples that aren't directly using math functions. Perhaps we should add this for the two tests directories too? test-journal and test-euler-quaternion are using functions from math.h so potentially they should be linking against -lm too. Maybe this isn't causing problems because they end up being builtins so they don't really need any symbols, but it would probably be cleaner to link against -lm anyway.

The LT_LIB_M macro already calls AC_SUBST(LIBM) itself so Cogl's configure script doesn't need to explicitly do it.

The gears example throws up warnings about sincos being previously undeclared. It is a GNU extension so it probably needs #define _GNU_SOURCE to use it. If we did that then it would probably also fix the problem because then Cogl would be using the builtins instead of the symbols from -lm. We should probably also fix that with a separate patch. I will make that now.
Comment 6 Neil Roberts 2013-04-05 17:11:58 UTC
Created attachment 240774 [details] [review]
Fix a warning about ‘sincos’ in examples/cogl-gles2-gears

‘sincos’ is a GNU extension. cogl-gles2-gears was using it without
defining _GNU_SOURCE so it was generating some annoying warnings. This
patch fixes it by making the example include config.h which will end
up defining _GNU_SOURCE.

In addition this patch adds a configure check for the function and
provides a fallback if it's not available.
Comment 7 Neil Roberts 2013-04-23 17:40:16 UTC
I've pushed the following patches to master and the cogl-1.14 branch:

a7b4930 build: Use LT_LIB_M to find the math library in a portable way
e3cc008 gitignore: Ignore the examples/cogl-gles2-gears executable
eb5c929 Fix a warning about ‘sincos’ in examples/cogl-gles2-gears
66a1aea Add $(LIBM) to the LDADD for all of the examples and tests

The last one is a replacement for the first attachment which makes all of the examples and tests link to -lm as I mentioned in comment 5

Thanks for looking at this.