Undefined reference to 'pthread_once'

Hello!
I'm building the latest OpenWrt with kernel 5.4 and I'm encountering a problem with pthread library. I'm building it fresh on a new virtual machine running Ubuntu 18.04.
Here are the error messages:

make[5]: Entering directory '/home/ziang/workspace/microchip-openwrt-5.4/build_dir/target-aarch64_generic_musl/linux-layerscape_armv8_64b/linux-5.4.42'
HOSTCC scripts/extract-cert
/home/ziang/workspace/microchip-openwrt-5.4/staging_dir/host/lib/libcrypto.a(libcrypto_la-eng_all.o): In function ENGINE_load_builtin_engines': eng_all.c:(.text+0x30): undefined reference to pthread_once'
/home/ziang/workspace/microchip-openwrt-5.4/staging_dir/host/lib/libcrypto.a(libcrypto_la-err.o): In function ERR_load_ERR_strings': err.c:(.text+0xb4e): undefined reference to pthread_once'
/home/ziang/workspace/microchip-openwrt-5.4/staging_dir/host/lib/libcrypto.a(libcrypto_la-err_all.o): In function ERR_load_crypto_strings': err_all.c:(.text+0x9f): undefined reference to pthread_once'
/home/ziang/workspace/microchip-openwrt-5.4/staging_dir/host/lib/libcrypto.a(libcrypto_la-c_all.o): In function OpenSSL_add_all_ciphers': c_all.c:(.text+0x9df): undefined reference to pthread_once'
/home/ziang/workspace/microchip-openwrt-5.4/staging_dir/host/lib/libcrypto.a(libcrypto_la-c_all.o): In function OpenSSL_add_all_digests': c_all.c:(.text+0x9ff): undefined reference to pthread_once'
/home/ziang/workspace/microchip-openwrt-5.4/staging_dir/host/lib/libcrypto.a(libcrypto_la-crypto_init.o):crypto_init.c:(.text+0x51): more undefined references to `pthread_once' follow
collect2: error: ld returned 1 exit status
scripts/Makefile.host:107: recipe for target 'scripts/extract-cert' failed
make[6]: *** [scripts/extract-cert] Error 1
Makefile:1105: recipe for target 'scripts' failed
make[5]: *** [scripts] Error 2

This error happens when I selected cfg80211 in the kernel_menuconfig which is needed by the WiFi driver I'm using.

I have tried the fix here and change the patch by adding -pthead, but the problem still exists:

./tools/mkimage/patches/210-link-libcrypto-static.patch:9:
HOSTLOADLIBES_mkimage +=
from: $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto")
to: $(shell pkg-config --libs --static libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto -pthread") -pthread

Any help is appreciated, thank you!

1 Like

Looks like you need to upgrade your Ubuntu.

[quote="[solved] Build error: undefined reference to `pthread_once' For Developers, post:1, topic:39119"]
OpenWRT
[/quote]

I'm running into the same issue. "Upgrade your Ubuntu" doesn't apply to me since I'm running Debian "testing" release. It's as up-to-date as any distro gets.

My guess is some dependency is missing for crypto packages or pthread is enabled by some other packages but not this one.

I've run "make distclean", restored my main .config, ran "make oldconfig" and I'm still getting this error even after the most recent "update scripts -a" and "install -a"

$ make -j1 V=sc
make[1]: Entering directory '/usr/src/openwrt'
make[2]: Entering directory '/usr/src/openwrt'
make[3]: Entering directory '/usr/src/openwrt/target/linux'
make[4]: Entering directory '/usr/src/openwrt/target/linux/ipq40xx'
rm -f /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/localversion
/usr/src/openwrt/scripts/kconfig.pl  + /usr/src/openwrt/target/linux/generic/config-5.4 /usr/src/openwrt/target/linux/ipq40xx/config-5.4 > /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.target
awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' /usr/src/openwrt/.config >> /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.target
echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.target
echo "# CONFIG_KALLSYMS_ALL is not set" >> /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.target
echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.target
/usr/src/openwrt/scripts/package-metadata.pl kconfig /usr/src/openwrt/tmp/.packageinfo /usr/src/openwrt/.config 5.4 > /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.override
/usr/src/openwrt/scripts/kconfig.pl 'm+' '+' /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.target /dev/null /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.override > /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set
mv /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.old
grep -v INITRAMFS /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.old > /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set
echo 'CONFIG_INITRAMFS_SOURCE=""' >> /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set
echo '# CONFIG_INITRAMFS_FORCE is not set' >> /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set
rm -rf /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/modules
cmp -s /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.prev || { cp /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config; cp /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.prev; }
export MAKEFLAGS= ; [ -d /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/user_headers ] || make -C /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52 KCFLAGS="-fmacro-prefix-map=/usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi=target-arm_cortex-a7+neon-vfpv4_musl_eabi" HOSTCFLAGS="-O2 -I/usr/src/openwrt/staging_dir/host/include  -Wall -Wmissing-prototypes -Wstrict-prototypes" CROSS_COMPILE="arm-openwrt-linux-muslgnueabi-" ARCH="arm" KBUILD_HAVE_NLS=no KBUILD_BUILD_USER="" KBUILD_BUILD_HOST="" KBUILD_BUILD_TIMESTAMP="Sun Aug 23 23:51:41 2020" KBUILD_BUILD_VERSION="0" HOST_LOADLIBES="-L/usr/src/openwrt/staging_dir/host/lib" KBUILD_HOSTLDLIBS="-L/usr/src/openwrt/staging_dir/host/lib" CONFIG_SHELL="bash" V=1  cmd_syscalls= KERNELRELEASE=5.4.52 CC="arm-openwrt-linux-muslgnueabi-gcc" INSTALL_HDR_PATH=/usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/user_headers headers_install
grep '=[ym]' /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.config.set | LC_ALL=C sort | mkhash md5 > /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.vermagic
touch /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.configured
rm -f /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/vmlinux /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/System.map
make -C /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52 KCFLAGS="-fmacro-prefix-map=/usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi=target-arm_cortex-a7+neon-vfpv4_musl_eabi" HOSTCFLAGS="-O2 -I/usr/src/openwrt/staging_dir/host/include  -Wall -Wmissing-prototypes -Wstrict-prototypes" CROSS_COMPILE="arm-openwrt-linux-muslgnueabi-" ARCH="arm" KBUILD_HAVE_NLS=no KBUILD_BUILD_USER="" KBUILD_BUILD_HOST="" KBUILD_BUILD_TIMESTAMP="Sun Aug 23 23:51:41 2020" KBUILD_BUILD_VERSION="0" HOST_LOADLIBES="-L/usr/src/openwrt/staging_dir/host/lib" KBUILD_HOSTLDLIBS="-L/usr/src/openwrt/staging_dir/host/lib" CONFIG_SHELL="bash" V=1  cmd_syscalls= KERNELRELEASE=5.4.52 CC="arm-openwrt-linux-muslgnueabi-gcc" modules
make[5]: Entering directory '/usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52'
make -f ./scripts/Makefile.build obj=arch/arm/tools uapi
make -f ./scripts/Makefile.build obj=scripts/basic
rm -f .tmp_quiet_recordmcount
make -f ./scripts/Makefile.build obj=scripts/dtc
make -f ./scripts/Makefile.build obj=scripts
  gcc -Wp,-MD,scripts/.extract-cert.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89  -O2 -I/usr/src/openwrt/staging_dir/host/include  -Wall -Wmissing-prototypes -Wstrict-prototypes   -I/usr/src/openwrt/staging_dir/host/include -I./tools/include    -o scripts/extract-cert scripts/extract-cert.c -L/usr/src/openwrt/staging_dir/host/lib -lcrypto
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-eng_all.o): in function `ENGINE_load_builtin_engines':
eng_all.c:(.text+0x30): undefined reference to `pthread_once'
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-err.o): in function `ERR_load_ERR_strings':
err.c:(.text+0xd2e): undefined reference to `pthread_once'
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-err_all.o): in function `ERR_load_crypto_strings':
err_all.c:(.text+0x9f): undefined reference to `pthread_once'
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-c_all.o): in function `OpenSSL_add_all_ciphers':
c_all.c:(.text+0x9df): undefined reference to `pthread_once'
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-c_all.o): in function `OpenSSL_add_all_digests':
c_all.c:(.text+0x9ff): undefined reference to `pthread_once'
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-crypto_init.o):crypto_init.c:(.text+0x51): more undefined references to `pthread_once' follow
collect2: error: ld returned 1 exit status
make[6]: *** [scripts/Makefile.host:107: scripts/extract-cert] Error 1
make[5]: *** [Makefile:1101: scripts] Error 2
make[5]: Leaving directory '/usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52'
make[4]: *** [Makefile:24: /usr/src/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-ipq40xx_generic/linux-5.4.52/.modules] Error 2
make[4]: Leaving directory '/usr/src/openwrt/target/linux/ipq40xx'
make[3]: *** [Makefile:13: compile] Error 2
make[3]: Leaving directory '/usr/src/openwrt/target/linux'
time: target/linux/compile#0.86#0.33#1.17
make[2]: *** [target/Makefile:25: target/linux/compile] Error 2
make[2]: Leaving directory '/usr/src/openwrt'
make[1]: *** [target/Makefile:18: /usr/src/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/stamp/.target_compile] Error 2
make[1]: Leaving directory '/usr/src/openwrt'
make: *** [/usr/src/openwrt/include/toplevel.mk:235: world] Error 2

cheers,
grant

I had the same problem. I solved this by modify the file
openwrt/build_dir/target-x86_64_musl/linux-x86_64/linux-5.4.79/scripts/Makefile
Line 27 from

HOSTLDLIBS_extract-cert = -lcrypto

To

HOSTLDLIBS_extract-cert = -lcrypto -lpthread
4 Likes

Thanks for sharing this fix. I ran into this after making some changes to the kernel config for a sunxi64 target. Added -lpthread to the flags and everything compiled as expected :grinning:

1 Like

I was happy to find a solution here in the forum but it would be great, if it could be fixed for the community.
Has someone opened a bug issue for that problem?
My search did not produce any results, but i want to be safe not to create a duplicate one.

This topic was automatically closed 0 minutes after the last reply. New replies are no longer allowed.