Skip to contentSkip to conversation

dnsmasq: fix static linking

PATCH New Vicente Olivert Riera 2 participants 2 messages Mar 4, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dnsmasq: fix static linking

Append -pthread to LIBS to fix a static linking error like this one:

/home/test/test/2/output/host/usr/mipsel-buildroot-linux-uclibc/sysroot/usr/lib/libdbus-1.a(libdbus_1_la-dbus-sysdeps-pthread.o):
In function `_dbus_platform_cmutex_new':
dbus-sysdeps-pthread.c:(.text+0x30): undefined reference to
`pthread_mutex_init'

Fixes:
http://autobuild.buildroot.net/results/161/161446dde7e8e774773eb2b34fd555f5ac22dd02/

---
 package/dnsmasq/dnsmasq.mk |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
package/dnsmasq/dnsmasq.mk +2 -1
index 9bf9b84..a7e6958 100644
@@ -61,6 +61,7 @@ endif
 
 ifeq ($(BR2_PACKAGE_DBUS),y)
 	DNSMASQ_DEPENDENCIES += host-pkgconf dbus
+	DNSMASQ_LIBS += $(if $(BR2_PREFER_STATIC_LIB),-pthread)
 endif
 
 define DNSMASQ_FIX_PKGCONFIG
@@ -85,7 +86,7 @@ define DNSMASQ_BUILD_CMDS
 	$(DNSMASQ_ENABLE_DBUS)
 	$(DNSMASQ_ENABLE_LUA)
 	$(DNSMASQ_ENABLE_CONNTRACK)
-	$(DNSMASQ_MAKE_ENV) $(MAKE1) -C $(@D) $(DNSMASQ_MAKE_OPT) all$(DNSMASQ_I18N)
+	$(DNSMASQ_MAKE_ENV) $(MAKE1) -C $(@D) $(DNSMASQ_MAKE_OPT) LIBS+="$(DNSMASQ_LIBS)" all$(DNSMASQ_I18N)
 endef
 
 define DNSMASQ_INSTALL_TARGET_CMDS
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 dnsmasq: fix static linking

Dear Vicente Olivert Riera,

Quoted 7 lines · Vicente Olivert Riera

Append -pthread to LIBS to fix a static linking error like this one:

/home/test/test/2/output/host/usr/mipsel-buildroot-linux-uclibc/sysroot/usr/lib/libdbus-1.a(libdbus_1_la-dbus-sysdeps-pthread.o):
In function `_dbus_platform_cmutex_new':
dbus-sysdeps-pthread.c:(.text+0x30): undefined reference to
`pthread_mutex_init'

Quoted 5 lines

Fixes:

   http://autobuild.buildroot.net/results/161/161446dde7e8e774773eb2b34fd555f5ac22dd02/

Thanks, but I don't think it's the best fix for the problem.

package/dnsmasq/dnsmasq.mk endif · line 65

Quoted 4 lines

ifeq ($(BR2_PACKAGE_DBUS),y)

package/dnsmasq/dnsmasq.mk +1 -0
 	DNSMASQ_DEPENDENCIES += host-pkgconf dbus
+	DNSMASQ_LIBS += $(if $(BR2_PREFER_STATIC_LIB),-pthread)
 endif

dnsmasq properly uses pkg-config to find which library to link against, and the dbus-1.pc properly lists -lrt and -lpthread in Libs.private (i.e libraries needed in the link when linking statically).

The problem is just that the dnsmasq Makefile does not call pkg-config with the --static option when being built statically. Compare the output of:

$ ./output/host/usr/bin/pkg-config --libs dbus-1
-L/home/thomas/projets/buildroot/output/host/usr/mipsel-buildroot-linux-uclibc/sysroot/usr/lib -ldbus-1

against the output of:

$ ./output/host/usr/bin/pkg-config --static --libs dbus-1
-L/home/thomas/projets/buildroot/output/host/usr/mipsel-buildroot-linux-uclibc/sysroot/usr/lib -ldbus-1 -lpthread -lrt

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com