static build : undefined reference to pthread_rwlock_init
Daryes opened this issue · 3 comments
This one happens only on Ubuntu 18.04, with pixelserv-tls from v2.1.2 to v2.2.0 when building a static linked binary.
No errors with p-tls 2.1.0.
This set of commands will result in the undefined reference to pthread... compilation error, and only on Ubuntu 18.04
./configure --enable-static
make
The error log :
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(threads_pthread.o): In function `CRYPTO_THREAD_lock_new':
(.text+0x25): undefined reference to `pthread_rwlock_init'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(threads_pthread.o): In function `CRYPTO_THREAD_read_lock':
(.text+0x55): undefined reference to `pthread_rwlock_rdlock'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(threads_pthread.o): In function `CRYPTO_THREAD_write_lock':
(.text+0x75): undefined reference to `pthread_rwlock_wrlock'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(threads_pthread.o): In function `CRYPTO_THREAD_unlock':
(.text+0x95): undefined reference to `pthread_rwlock_unlock'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(threads_pthread.o): In function `CRYPTO_THREAD_lock_free':
(.text+0xba): undefined reference to `pthread_rwlock_destroy'
collect2: error: ld returned 1 exit status
Makefile:412: recipe for target 'pixelserv-tls' failed
make[1]: *** [pixelserv-tls] Error 1
When using the -lpthread setting in the configure command, the binary will be built without problem :
./configure --enable-static LIBS="-lpthread"
make
(or ./configure --enable-static LIBS="-lpthread" CFLAGS="-m32" CXXFLAGS="-m32" LDFLAGS="-m32"
for the x86 binary build)
Strange one, as this error doesn't happen on Ubuntu 16.04.
Thanks for the detailed report. I finally have a Ubuntu 18.04 VM up and running to play around this issue.
Turns out if we swap the order of -lpthread and the two openssl libraries, the static build will succeed on 18.04. Your append of LIBS=-lpthread achieves a similar effect.
As for why it wasn't an issue in 16.04 and how that solves it in 18.04, I'm clueless frankly. It's a bit tricky to compile static binary and generally not recommended. Purely luck static link works out for pixelserv-tls.
I'll update the tracker once the change is pushed.
As long as I'm able to build the static build, I'm not complaining about the how :)
This aside, the lpthread order seems to be new with Ubuntu 18.04. I didn't have to search much to find some recent information about this, and understanding the explanation might be another subtle change in the build tools, that are updated with the new LTS version.
Might be similar with some warnings appearing when compiling after a kernel update, Only this time, it wasn't just an information message but a real error.