CODEBLOCKS 编译 pthread 引发错误

编译打包和其他
回复
qicksand
帖子: 4
注册时间: 2009-07-13 14:26

CODEBLOCKS 编译 pthread 引发错误

#1

帖子 qicksand » 2009-07-14 10:24

刚接触 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>
qicksand
帖子: 4
注册时间: 2009-07-13 14:26

Re: CODEBLOCKS 编译 pthread 引发错误

#2

帖子 qicksand » 2009-07-14 15:00

自己跟个。
我看到有个帖子类似遭遇我这样的问题。但未究其所以然。我的问题依然存在。那位大侠感兴趣,帮我看看。
http://www.lslnet.com/linux/dosc1/04/linux-126594.htm

继续找。。。
qicksand
帖子: 4
注册时间: 2009-07-13 14:26

Re: CODEBLOCKS 编译 pthread 引发错误

#3

帖子 qicksand » 2009-07-14 21:07

:em02 自己解决哪.!:)...
在shell 命令模式下 # gcc thread.c -lpthread 链接正常
但在code::bloksl下添加静态库libpthread.a ,编译提示库调用常量未定义。折腾一下午,四处询问没求解。
晚上没事将开发教程翻翻。突然在GCC编译器处提到,'gcc 在编译时默认使用动态库'。*.a 为静态函数库, *.so 为动态链接库。于是将配置文件指向配置为libpthread.so。
编译通过,终于搞定。。。
就这问题浪费我不少时间。。截图如下:?咋个传图。倒腾。。:)
感谢各位看官。。。希望这次经历对你也有启发。
wangchuanyan
帖子: 8
注册时间: 2009-09-25 21:09

Re: CODEBLOCKS 编译 pthread 引发错误

#4

帖子 wangchuanyan » 2009-10-15 17:12

这个问题有没有解决
wangchuanyan
帖子: 8
注册时间: 2009-09-25 21:09

Re: CODEBLOCKS 编译 pthread 引发错误

#5

帖子 wangchuanyan » 2009-10-15 17:12

qicksand, 问题有没有解决
回复