CODEBLOCKS 编译 pthread 引发错误

 

刚接触 CODEBLOCKS 在fedora9 下配置好环境后,复制了书上的一段线程应用代码。遭遇两个迷惑问题。未解决。
1.开始编译,提示pthread_create 未定义(用到:res = pthread_create(&thread[no], NULL, thrd_func, (void*)no);)。
上网原因:问题原因: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
于是,在CODEBLOCKS 链接器设置项中添加libpthread.a,查找到该文件在/usr/bin/lib 中(注不同环境路径可能有异)。
2.再次编译。未定义的问题解决了,但紧接着更大的问题 来了。
debug Information:
/usr/lib/libpthread.a(pthread_create.o)||In function `pthread_create':|
(.text+0xa2f)||undefined reference to `_dl_stack_flags'|
/usr/lib/libpthread.a(pthread_create.o)||In function `pthread_create':|
(.text+0xbe5)||undefined reference to `_dl_stack_flags'|
/usr/lib/libpthread.a(ptw-pause.o)||In function `__pause_nocancel':|
(.text+0x18)||undefined reference to `__syscall_error'|
/usr/lib/libpthread.a(ptw-pause.o)||In function `__pause_nocancel':|
(.text+0x3b)||undefined reference to `__syscall_error'|
/usr/lib/libpthread.a(init.o)||In function `__pthread_initialize_minimal':|
(.text+0x1c)||undefined reference to `__libc_setup_tls'|
/usr/lib/libpthread.a(init.o)||In function `__pthread_initialize_minimal':|
(.text+0x236)||undefined reference to `_dl_init_static_tls'|
/usr/lib/libpthread.a(init.o)||In function `__pthread_initialize_minimal':|
(.text+0x240)||undefined reference to `_dl_wait_lookup_done'|
/usr/lib/libpthread.a(ptw-read.o)||In function `__read_nocancel':|
(.text+0x26)||undefined reference to `__syscall_error'|
/usr/lib/libpthread.a(ptw-read.o)||In function `__read_nocancel':|
(.text+0x56)||undefined reference to `__syscall_error'|
/usr/lib/libpthread.a(ptw-open.o)||In function `__open_nocancel':|
(.text+0x26)||undefined reference to `__syscall_error'|
/usr/lib/libpthread.a(ptw-open.o)||In function `__open_nocancel':|
(.text+0x56)||undefined reference to `__syscall_error'|
/usr/lib/libpthread.a(sigaction.o)||In function `__libc_sigaction':|
(.text+0x46)||undefined reference to `_dl_sysinfo_dso'|
||=== 已完成构建: 12 个错误, 0 个警告 ===|

看到这些就晕菜了。那位前辈能指点迷津。感谢。
文件有预定#include <pthread.h>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值