package.snappy: fix static builds with threads
authorYann E. MORIN <yann.morin.1998@free.fr>
Sat, 1 Oct 2016 19:04:47 +0000 (21:04 +0200)
committerPeter Korsgaard <peter@korsgaard.com>
Sun, 2 Oct 2016 19:21:22 +0000 (21:21 +0200)
For some toolchains, libstdc++ uses pthread symbols:

    .../lib/libstdc++.a(eh_alloc.o): In function `__gnu_cxx::__mutex::lock()':
    eh_alloc.cc:(.text._ZN9__gnu_cxx7__mutex4lockEv[_ZN9__gnu_cxx7__mutex4lockEv]+0x2):
    undefined reference to `pthread_mutex_lock'

and a lot of other pthread symbols...

However, when doing a static build, there is no way for the linker to know
what library to link in, so the build fails miserably if -pthread is not
specified at link time.

Fixes:
    http://autobuild.buildroot.org/results/15e/15ecaa23f0116e8120b3d62e553c838f0303df35/
    http://autobuild.buildroot.org/results/f0a/f0abe301816e39eb4ae26d3e8cd42d90901d5ac5/

[Peter: only perform workaround if toolchain has threads support, tweak comment]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
package/snappy/snappy.mk

index b00dddf6cf3817133f5af4894c922585928192c1..6f89cf11cbe04934c632c6997d918baee377d3fb 100644 (file)
@@ -16,4 +16,13 @@ SNAPPY_INSTALL_STAGING = YES
 # Disable tests
 SNAPPY_CONF_OPTS = --disable-gtest
 
+# libsnappy links with libstdc++. Some libstdc++/arch variants use
+# pthread symbols for internal locking if built with thead
+# support. libstdc++ does not have a .pc file, and its .la file does
+# not mention -pthread.  So, static linkig to libstdc++ will fail if
+# -pthread is not explicity linked to. Only do that for static builds.
+ifeq ($(BR2_STATIC_LIBS)$(BR2_TOOLCHAIN_HAS_THREADS),yy)
+SNAPPY_CONF_OPTS += LIBS=-pthread
+endif
+
 $(eval $(autotools-package))