../lib//libscsdblog.so: undefined reference to `pthread_atfork'

本文介绍了一种在编译过程中遇到的与-lpthread相关的链接错误,并分享了解决该问题的方法:通过调整链接库的顺序将-lpthread置于末尾。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码中遇到这个问题,但是在makefile中已经添加了-lpthread.

最后发现问题时,引入库的顺序,把-lpthread放在最后就可以了。

wang@ubuntu:~$ cd ~/dog_ws wang@ubuntu:~/dog_ws$ cat build/CMakeFiles/CMakeError.log Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output: Change Dir: /home/wang/dog_ws/build/CMakeFiles/CMakeTmp Run Build Command(s):/usr/bin/make cmTC_c5a31/fast && /usr/bin/make -f CMakeFiles/cmTC_c5a31.dir/build.make CMakeFiles/cmTC_c5a31.dir/build make[1]: 进入目录“/home/wang/dog_ws/build/CMakeFiles/CMakeTmp” Building C object CMakeFiles/cmTC_c5a31.dir/src.c.o /usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_c5a31.dir/src.c.o -c /home/wang/dog_ws/build/CMakeFiles/CMakeTmp/src.c Linking C executable cmTC_c5a31 /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_c5a31.dir/link.txt --verbose=1 /usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -rdynamic CMakeFiles/cmTC_c5a31.dir/src.c.o -o cmTC_c5a31 /usr/bin/ld: CMakeFiles/cmTC_c5a31.dir/src.c.o: in function `main': src.c:(.text+0x46): undefined reference to `pthread_create' /usr/bin/ld: src.c:(.text+0x52): undefined reference to `pthread_detach' /usr/bin/ld: src.c:(.text+0x63): undefined reference to `pthread_join' collect2: error: ld returned 1 exit status make[1]: *** [CMakeFiles/cmTC_c5a31.dir/build.make:87:cmTC_c5a31] 错误 1 make[1]: 离开目录“/home/wang/dog_ws/build/CMakeFiles/CMakeTmp” make: *** [Makefile:121:cmTC_c5a31/fast] 错误 2 Source file was: #include <pthread.h> void* test_func(void* data) { return data; } int main(void) { pthread_t thread; pthread_create(&thread, NULL, test_func, NULL); pthread_detach(thread); pthread_join(thread, NULL); pthread_atfork(NULL, NULL, NULL); pthread_exit(NULL); return 0; } Determining if the function pthread_create exists in the pthreads failed with the following output: Change Dir: /home/wang/dog_ws/build/CMakeFiles/CMakeTmp Run Build Command(s):/usr/bin/make cmTC_5aede/fast && /usr/bin/make -f CMakeFiles/cmTC_5aede.dir/build.make CMakeFiles/cmTC_5aede.dir/build make[1]: 进入目录“/home/wang/dog_ws/build/CMakeFiles/CMakeTmp” Building C object CMakeFiles/cmTC_5aede.dir/CheckFunctionExists.c.o /usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_5aede.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c Linking C executable cmTC_5aede /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5aede.dir/link.txt --verbose=1 /usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_5aede.dir/CheckFunctionExists.c.o -o cmTC_5aede -lpthreads /usr/bin/ld: 找不到 -lpthreads collect2: error: ld returned 1 exit status make[1]: *** [CMakeFiles/cmTC_5aede.dir/build.make:87:cmTC_5aede] 错误 1 make[1]: 离开目录“/home/wang/dog_ws/build/CMakeFiles/CMakeTmp” make: *** [Makefile:121:cmTC_5aede/fast] 错误 2
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值