您的位置:首页 > Web前端

thread编译出错解决方法

2010-10-27 21:12 399 查看
编译:
zjz@ubuntu:~/scr/AT91SAM9260/BaseExp/4.thread/thread$ gcc thread.c
/tmp/cch3hL4i.o: In function `main':
thread.c:(.text+0xca): undefined reference to `pthread_create'
thread.c:(.text+0x112): undefined reference to `pthread_create'
thread.c:(.text+0x149): undefined reference to `pthread_join'
thread.c:(.text+0x15d): undefined reference to `pthread_join'
collect2: ld returned 1 exit status

产生原因:
     pthread 库不是 Linux 系统默认的库,连接时需要使用静态库libpthread.a,所以在使用pthread_create()创建线程,和其他一些与线程操作相关的函数时,需要链接该库。

    这个错误跟以前遇到的那个使用<math.h>头文件时,很多数学函数的找不到的提示类似,那时候是在编译的时候添加“-lm”选项。
而此处产生这个问题原因是:

解决方法:
    在编译中要加 -lpthread选项
zjz@ubuntu:~/scr/AT91SAM9260/BaseExp/4.thread/thread$ gcc thread.c -lpthread
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息