GNOME Bugzilla – Bug 697330
Fails to build with the gold linker due to missing reference to libm
Last modified: 2013-04-23 17:40:16 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
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.
Created attachment 240719 [details] [review] build: Use LT_LIB_M to find the math library in a portable way
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.
Created attachment 240721 [details] [review] gitignore: Ignore the examples/cogl-gles2-gears executable
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.
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.
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.