tests: Fix undefined references to pthread.
When building NetworkManager with --enable-tests
(The default) and slibtool (https://dev.midipix.org/cross/slibtool) the build fails in many places with undefined references to pthreads.
rdlibtool --tag=CC --mode=link gcc -Wall -Werror -Wextra -Wdeclaration-after-statement -Wfloat-equal -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wpointer-arith -Wshadow -Wshift-negative-value -Wstrict-prototypes -Wundef -Wvla -Wno-duplicate-decl-specifier -Wno-format-truncation -Wno-format-y2k -Wno-missing-field-initializers -Wno-pragmas -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Warray-bounds -Wunused-value -Wcast-function-type -Wimplicit-fallthrough -fno-strict-aliasing -fdata-sections -ffunction-sections -Wl,--gc-sections -g -O2 -o src/core/dhcp/tests/test-dhcp-dhclient src/core/dhcp/tests/test_dhcp_dhclient-test-dhcp-dhclient.o src/core/libNetworkManagerTest.la -ldl
rdlibtool: lconf: {.name="libtool"}.
rdlibtool: fdcwd: {.fdcwd=AT_FDCWD, .realpath="/tmp/NetworkManager"}.
rdlibtool: lconf: fstatat(AT_FDCWD,".",...) = 0 {.st_dev = 45, .st_ino = 29018}.
rdlibtool: lconf: openat(AT_FDCWD,"libtool",O_RDONLY,0) = 3.
rdlibtool: lconf: found "/tmp/NetworkManager/libtool".
rdlibtool: link: gcc src/core/dhcp/tests/test_dhcp_dhclient-test-dhcp-dhclient.o src/core/.libs/libNetworkManagerTest.a -Wall -Werror -Wextra -Wdeclaration-after-statement -Wfloat-equal -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wpointer-arith -Wshadow -Wshift-negative-value -Wstrict-prototypes -Wundef -Wvla -Wno-duplicate-decl-specifier -Wno-format-truncation -Wno-format-y2k -Wno-missing-field-initializers -Wno-pragmas -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Warray-bounds -Wunused-value -Wcast-function-type -Wimplicit-fallthrough -fno-strict-aliasing -fdata-sections -ffunction-sections -Wl,--gc-sections -g -O2 -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -ludev -ldl -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -luuid -ldl -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lssl3 -lsmime3 -lnss3 -lnssutil3 -lplds4 -lplc4 -lnspr4 -ldl -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -ludev -lndp -ldl -lpsl -lcurl -ldl -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -ludev -o src/core/dhcp/tests/.libs/test-dhcp-dhclient
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/core/.libs/libNetworkManagerTest.a(libnm_systemd_shared_la-hashmap.o): undefined reference to symbol 'pthread_once@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/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 1634: (see child process error messages).
rdlibtool: < returned to > slbt_exec_link(), line 1954.
make[2]: *** [Makefile:10904: src/core/dhcp/tests/test-dhcp-dhclient] Error 2
make[2]: Leaving directory '/tmp/NetworkManager'
make[1]: *** [Makefile:18351: install-recursive] Error 1
make[1]: Leaving directory '/tmp/NetworkManager'
make: *** [Makefile:19202: install] Error 2
This can be fixed by utilizing ax_pthread.m4
(https://github.com/autoconf-archive/autoconf-archive/blob/master/m4/ax_pthread.m4) and adding $(PTHREAD_LIBS)
accordingly to src_core_libNetworkManagerTest_la_LIBADD
.
GNU libtool does not expose this issue because it silently adds -pthread
for some reason....
I enabled the threads requirement only for the tests in configure.ac.