Undefined reference to -lpthread with slibtool
I am trying to build wayland with slibtool instead of GNU libtool, but it is failing with a undefined reference to pthread_join@@GLIBC_2.2.5
.
rdlibtool --tag=CC --mode=link gcc -Wall -Wextra -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -g -O2 -o display-test tests/display-test.o protocol/tests-protocol.o libtest-runner.la
rdlibtool: link: gcc tests/display-test.o protocol/tests-protocol.o .libs/libtest-runner.a -Wall -Wextra -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -g -O2 -L.libs -lwayland-client -lwayland-server -ldl -lffi -o .libs/display-test
/usr/bin/ld: tests/display-test.o: undefined reference to symbol 'pthread_join@@GLIBC_2.2.5'
/usr/bin/ld: /lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
rdlibtool: exec error upon slbt_exec_link_create_executable(), line 1580: (see child process error messages).
rdlibtool: < returned to > slbt_exec_link(), line 1845.
make[2]: *** [Makefile:1550: display-test] Error 2
make[2]: Leaving directory '/tmp/wayland'
make[1]: *** [Makefile:2039: all-recursive] Error 1
make[1]: Leaving directory '/tmp/wayland'
make: *** [Makefile:1241: all] Error 2
After discussing it with the slibtool upstream and was told that libtest_runner
is missing a -lpthread
and this has gone unnoticed since it appears libtool automatically and silently adds it...
This can be easily solved by adding -lpthread
.
diff --git a/Makefile.am b/Makefile.am
index 489f581..8cf34a5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -227,7 +227,7 @@ libtest_runner_la_LIBADD = \
libwayland-client.la \
libwayland-server.la \
libtest-helpers.la \
- $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS)
+ $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS) -lpthread
array_test_SOURCES = tests/array-test.c
array_test_LDADD = libtest-runner.la
However there may be a better way than hardcoding it?
I have attached a complete build log for reference. wayland.log
I have also attempted to bisect this issue and found it was exposed in commit aa51a833.