Skip to content

build: Fix undefined pthread references

orbea requested to merge orbea/spice:pthread into master

When building spice with slibtool (https://dev.midipix.org/cross/slibtool) it fails with undefined references to pthread.

rdlibtool --tag=CXX --mode=link g++ -fno-common -W -Waddress -Waggressive-loop-optimizations -Wall -Wattributes -Wbool-compare -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdate-time -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion -Wduplicated-cond -Wempty-body -Wendif-labels -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wformat-zero-length -Wframe-address -Wfree-nonheap-object -Whsa -Wignored-attributes -Wignored-qualifiers -Winit-self -Wint-to-pointer-cast -Winvalid-memory-model -Winvalid-pch -Wlogical-not-parentheses -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-braces -Wmissing-field-initializers -Wmissing-include-dirs -Wmultichar -Wnarrowing -Wnonnull -Wnonnull-compare -Wodr -Wopenmp-simd -Woverflow -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpragmas -Wreturn-local-addr -Wreturn-type -Wscalar-storage-order -Wsequence-point -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstrict-aliasing -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch -Wswitch-bool -Wsync-nand -Wtautological-compare -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvolatile-register-var -Wwrite-strings -Warray-bounds=2 -Wnormalized=nfc -Wunused-const-variable=2 -Wno-sign-compare -Wno-unused-parameter -Wno-format-nonliteral -Wframe-larger-than=20460 -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-final-methods -Wno-suggest-final-types -Wno-array-bounds -Wno-narrowing -Wno-missing-field-initializers -Wshadow -g -O2 -fno-exceptions -fno-check-new -version-info 15:1:14 -no-undefined -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,--no-copy-dt-needed-entries -Wl,--version-script=./spice-server.syms -o libspice-server.la -rpath /usr/local/lib libserver.la

rdlibtool: lconf: {.name="libtool"}.
rdlibtool: fdcwd: {.fdcwd=AT_FDCWD, .realpath="/tmp/spice/server"}.
rdlibtool: lconf: fstatat(AT_FDCWD,".",...) = 0 {.st_dev = 45, .st_ino = 317362}.
rdlibtool: lconf: openat(AT_FDCWD,"libtool",O_RDONLY,0) = -1 [ENOENT].
rdlibtool: lconf: openat(AT_FDCWD,"../",O_DIRECTORY,0) = 3.
rdlibtool: lconf: fstat(3,...) = 0 {.st_dev = 45, .st_ino = 317167}.
rdlibtool: lconf: openat(3,"libtool",O_RDONLY,0) = 4.
rdlibtool: lconf: found "/tmp/spice/libtool".
rdlibtool: link: ln -s libspice-server.so.def .libs/libspice-server.so.def.linux
rdlibtool: link: ln -s libspice-server.so.def.linux .libs/libspice-server.so.def.host
rdlibtool: link: ln -s /dev/null .libs/libspice-server.a.disabled
rdlibtool: link: g++ -Wl,--whole-archive .libs/libserver.a -Wl,--no-whole-archive -fno-common -W -Waddress -Waggressive-loop-optimizations -Wall -Wattributes -Wbool-compare -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdate-time -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion -Wduplicated-cond -Wempty-body -Wendif-labels -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wformat-zero-length -Wframe-address -Wfree-nonheap-object -Whsa -Wignored-attributes -Wignored-qualifiers -Winit-self -Wint-to-pointer-cast -Winvalid-memory-model -Winvalid-pch -Wlogical-not-parentheses -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-braces -Wmissing-field-initializers -Wmissing-include-dirs -Wmultichar -Wnarrowing -Wnonnull -Wnonnull-compare -Wodr -Wopenmp-simd -Woverflow -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpragmas -Wreturn-local-addr -Wreturn-type -Wscalar-storage-order -Wsequence-point -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstrict-aliasing -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch -Wswitch-bool -Wsync-nand -Wtautological-compare -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvolatile-register-var -Wwrite-strings -Warray-bounds=2 -Wnormalized=nfc -Wunused-const-variable=2 -Wno-sign-compare -Wno-unused-parameter -Wno-format-nonliteral -Wframe-larger-than=20460 -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-final-methods -Wno-suggest-final-types -Wno-array-bounds -Wno-narrowing -Wno-missing-field-initializers -Wshadow -g -O2 -fno-exceptions -fno-check-new -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,--no-copy-dt-needed-entries -Wl,--version-script=./spice-server.syms -L.libs -lpixman-1 -lglib-2.0 -lopus -lssl -lcrypto -lm -lgio-2.0 -lgobject-2.0 -lglib-2.0 -ljpeg -llz4 -lrt -lpixman-1 -lgstapp-1.0 -lgstvideo-1.0 -lgstbase-1.0 -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lssl -lcrypto -lz -lm -lrt -lorc-0.4 -shared -fPIC -Wl,--no-undefined -Wl,-soname -Wl,libspice-server.so.1 -o .libs/libspice-server.so.1.14.1
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(glz-encoder-dict.o): in function `glz_enc_dictionary_create':
/tmp/spice/server/glz-encoder-dict.c:163: undefined reference to `pthread_rwlock_init'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(glz-encoder-dict.o): in function `glz_enc_dictionary_destroy':
/tmp/spice/server/glz-encoder-dict.c:231: undefined reference to `pthread_rwlock_destroy'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(glz-encoder-dict.o): in function `glz_dictionary_pre_encode':
/tmp/spice/server/glz-encoder-dict.c:598: undefined reference to `pthread_rwlock_rdlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(glz-encoder-dict.o): in function `__glz_dictionary_window_segs_realloc':
/tmp/spice/server/glz-encoder-dict.c:280: undefined reference to `pthread_rwlock_wrlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/spice/server/glz-encoder-dict.c:313: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(glz-encoder-dict.o): in function `glz_dictionary_post_encode':
/tmp/spice/server/glz-encoder-dict.c:609: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `glz_shared_dictionary_new(RedClient*, unsigned char, void*)':
/tmp/spice/server/image-encoders.cpp:698: undefined reference to `pthread_rwlock_init'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_glz_encode_lock':
/tmp/spice/server/image-encoders.cpp:573: undefined reference to `pthread_rwlock_wrlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_free_glz_drawables':
/tmp/spice/server/image-encoders.cpp:640: undefined reference to `pthread_rwlock_wrlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_free':
/tmp/spice/server/image-encoders.cpp:828: undefined reference to `pthread_rwlock_destroy'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_glz_get_restore_data':
/tmp/spice/server/image-encoders.cpp:671: undefined reference to `pthread_rwlock_wrlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_freeze_glz':
/tmp/spice/server/image-encoders.cpp:673: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_compress_glz':
/tmp/spice/server/image-encoders.cpp:1229: undefined reference to `pthread_rwlock_rdlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/spice/server/image-encoders.cpp:1293: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/spice/server/image-encoders.cpp:1232: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/spice/server/image-encoders.cpp:1297: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_glz_encode_unlock':
/tmp/spice/server/image-encoders.cpp:582: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(image-encoders.o): in function `image_encoders_free_glz_drawables':
/tmp/spice/server/image-encoders.cpp:647: undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(red-worker.o): in function `red_worker_run':
/tmp/spice/server/red-worker.cpp:1127: undefined reference to `pthread_create'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/spice/server/red-worker.cpp:1134: undefined reference to `pthread_setname_np'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libserver.a(red-worker.o): in function `red_worker_free':
/tmp/spice/server/red-worker.cpp:1153: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
rdlibtool: exec error upon slbt_exec_link_create_library(), line 1572: (see child process error messages).
rdlibtool: < returned to > slbt_exec_link(), line 2084.
make[4]: *** [Makefile:791: libspice-server.la] Error 2
make[4]: Leaving directory '/tmp/spice/server'
make[3]: *** [Makefile:943: install-recursive] Error 1
make[3]: Leaving directory '/tmp/spice/server'
make[2]: *** [Makefile:1103: install] Error 2
make[2]: Leaving directory '/tmp/spice/server'
make[1]: *** [Makefile:541: install-recursive] Error 1
make[1]: Leaving directory '/tmp/spice'
make: *** [Makefile:849: install] Error 2

This is because it builds with -no-undefined which is silently ignored by GNU libtool while slibtool respects the flag. The build failure will be also hidden with slibtool when -no-undefined is removed from libspice_server_la_LDFLAGS and it can be exposed with GNU libtool by changing it to -Wl,--no-undefined so that the flag is passed directly to the linker.

This is solved by adding -lpthread to libserver_la_LIBADD with the help of ax_pthread.m4 which is sourced from autoconf-archive.

https://github.com/autoconf-archive/autoconf-archive/blob/e68e8f6f62aea14b1ce980e75442d62abd668a95/m4/ax_pthread.m4

Merge request reports

Loading