thread_join.c:(.text+0x6f): undefined reference to `pthread_create' 问题的解决
2012-05-10 20:04
716 查看
今天在测试一个线程例子时,结果出现如下错误
[root@tom fzf]# gcc thread_join.c -o thread_join
/tmp/cc1HozRv.o: In function `main':
thread_join.c:(.text+0x6f): undefined reference to `pthread_create'
thread_join.c:(.text+0x91): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
问题原因:
pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a。
所以在使用pthread_create()创建线程,pthread_join()线程等待,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
问题解决如下:
在编译中要加 -lpthread参数
[root@tom fzf]# gcc thread_join.c -o thread_join -lpthread
[root@tom fzf]# gcc thread_join.c -o thread_join
/tmp/cc1HozRv.o: In function `main':
thread_join.c:(.text+0x6f): undefined reference to `pthread_create'
thread_join.c:(.text+0x91): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
问题原因:
pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a。
所以在使用pthread_create()创建线程,pthread_join()线程等待,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
问题解决如下:
在编译中要加 -lpthread参数
[root@tom fzf]# gcc thread_join.c -o thread_join -lpthread
相关文章推荐
- undefined reference to 'pthread_create'问题解决
- Linux下运行多线程——undefined reference to 'pthread_create'问题两种解决方法
- linux下开发,解决cocos2d-x中编译出现的一个小问题, undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
- 怎样彻底解决"undefined reference to `pthread_create'"问题
- 线程库编译问题: undefined reference to 'pthread_create'的解决
- undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create'问题解决
- c++多线程时 undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create' 问题解决
- linux undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create'问题解决
- linux 线程操作问题undefined reference to 'pthread_create'的解决办法(cmake)
- undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create' 问题解决[转]
- undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create'问题解决
- undefined reference to 'pthread_create'问题解决