一般向我们刚学线程的话,很容易出现一个错误如下:
/tmp/ccIysCg1.o: In function `eat_think':
read.c:(.text+0xc8): undefined reference to `pthread_mutex_trylock'
/tmp/ccIysCg1.o: In function `main':
read.c:(.text+0x1fa): undefined reference to `pthread_create'
read.c:(.text+0x21e): undefined reference to `pthread_create'
read.c:(.text+0x242): undefined reference to `pthread_create'
read.c:(.text+0x266): undefined reference to `pthread_create'
read.c:(.text+0x28a): undefined reference to `pthread_create'
read.c:(.text+0x29e): undefined reference to `pthread_join'
read.c:(.text+0x2b2): undefined reference to `pthread_join'
read.c:(.text+0x2c6): undefined reference to `pthread_join'
read.c:(.text+0x2da): undefined reference to `pthread_join'
read.c:(.text+0x2ee): undefined reference to `pthread_join'
即,出现未明确定义的函数的错误提示,那是因为线程函数编译时需要添加特殊编译选项:
gcc read.c -lpthread 比如最简单的编译命令,记住要在后加-lpthread选项,
并且头文件要记得包括:#include
这个头文件
至此错误可解决
阅读(13002) | 评论(0) | 转发(0) |