openssl: [TEMP. FIX] undefined reference to `pthread_atfork'

Hi. I’m trying to build Nginx with this script, but I get this error.

objs/addon/src/ngx_http_brotli_filter_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lpthread -lcrypt -lm ../pcre-8.41/.libs/libpcre.a ../openssl/.openssl/lib/libssl.a ../openssl/.openssl/lib/libcrypto.a -ldl ../libatomic_ops-7.6.0/src/libatomic_ops.a \
-Wl,-E
../openssl/.openssl/lib/libcrypto.a(threads_pthread.o): In function `openssl_init_fork_handlers':
threads_pthread.c:(.text+0x1ba): undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:309: objs/nginx] Error 1

I was able to build two weeks ago, so this issue must be new.

[EDIT] See the temporary fix.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (14 by maintainers)

Commits related to this issue

Most upvoted comments

So finally, It seems that the Nginx configuration file is quite odd. So the the temporary solution for now is a hack. After running the ./configure, in obj/Makefile, you should remove the first -lpthread and move the second to the end of the line, right before \. Since the github repo. of Nginx is just a mirror, I can’t submit an issue about this.

Thanks to all of you who supported me through this whole issue.

You should use “-pthread”, not “-lpthread”.

-lpthread will probably also work if you move it to the end of the libraries.

For some reason you’re also using a static version of all the libraries. I suggest you use shared versions instead if you can. Your OS should already provide shared versions of those libraries.

And i add -pthread to --with-cc-opt to build again, but get a same error:

...
-Wl,-z,relro -Wl,-z,now -pie -ldl -lpthread -lcrypt -lpcre ../openssl-master/.openssl/lib/libssl.a ../openssl-master/.openssl/lib/libcrypto.a -ldl -lz \
-Wl,-E
../openssl-master/.openssl/lib/libcrypto.a(threads_pthread.o):In function ‘fork_once_func’:
threads_pthread.c:(.text+0x16):undefined reference to 'pthread_atfork'

you should use “–with-ld-opt=-pthread”

For those who want a scripted temporary solution:

gawk -i inplace \
  '/pthread/ { sub(/-lpthread /, ""); sub(/-lpthread /, ""); sub(/\\/, "-lpthread \\"); print } ! /pthread/ { print }' \
  "objs/Makefile"

It looks to me like this is an order problem:

objs/addon/src/ngx_http_brotli_filter_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lpthread -lcrypt -lm ../pcre-8.41/.libs/libpcre.a ../openssl/.openssl/lib/libssl.a ../openssl/.openssl/lib/libcrypto.a -ldl ../libatomic_ops-7.6.0/src/libatomic_ops.a \
-Wl,-E

Shouldn’t -lpthread appear last to make sure the symbol references in libcrypto.a get properly resolved?