LINUX环境下PTHREAD链接报错的解决

本人对linux环境很不熟悉,今天做操作系统作业要在linux下用信号量以及pthread编程,使用codeblocks这个IDE,然后链接报错

/tmp/ccMNPEfl.o:在函数‘init_semaphores()’中:
source.cpp:(.text+0×212):对‘sem_init’未定义的引用
source.cpp:(.text+0x22e):对‘sem_init’未定义的引用
source.cpp:(.text+0x24a):对‘sem_init’未定义的引用
/tmp/ccMNPEfl.o:在函数‘ProducerProcess(void*)’中:
source.cpp:(.text+0x2a8):对‘sem_wait’未定义的引用
source.cpp:(.text+0x2b4):对‘sem_wait’未定义的引用
source.cpp:(.text+0x31c):对‘sem_post’未定义的引用
source.cpp:(.text+0×328):对‘sem_post’未定义的引用
/tmp/ccMNPEfl.o:在函数‘ConsumerProcess(void*)’中:
source.cpp:(.text+0x34c):对‘sem_wait’未定义的引用
source.cpp:(.text+0×358):对‘sem_wait’未定义的引用
source.cpp:(.text+0x3bd):对‘sem_post’未定义的引用
source.cpp:(.text+0x3c9):对‘sem_post’未定义的引用
/tmp/ccMNPEfl.o:在函数‘init_threads()’中:
source.cpp:(.text+0×417):对‘pthread_create’未定义的引用
source.cpp:(.text+0×431):对‘pthread_join’未定义的引用
source.cpp:(.text+0x45c):对‘pthread_create’未定义的引用
source.cpp:(.text+0×476):对‘pthread_join’未定义的引用
collect2: 错误: ld 返回 1

后来查了半天发现是链接器要加上参数 -pthread

记录一下,说不定以后又忘了呢。。~

posted on 2013-12-17 23:02  莫扎特也是程序猿  阅读(1554)  评论(0)    收藏  举报

导航