CODEBLOCKS 编译 pthread 引发错误
发表于 : 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>
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>