Categories
不学无术

linux环境下pthread链接报错的解决

本人对linux环境很不熟悉,今天做操作系统作业要在linux下用信号量以及pthread编程,使用codeblocks这个IDE,然后链接报错
/tmp/ccMNPEfl.o:在函数‘init_semaphores()’中:
source.cpp:(.text+0x212):对‘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+0x328):对‘sem_post’未定义的引用
/tmp/ccMNPEfl.o:在函数‘ConsumerProcess(void*)’中:
source.cpp:(.text+0x34c):对‘sem_wait’未定义的引用
source.cpp:(.text+0x358):对‘sem_wait’未定义的引用
source.cpp:(.text+0x3bd):对‘sem_post’未定义的引用
source.cpp:(.text+0x3c9):对‘sem_post’未定义的引用
/tmp/ccMNPEfl.o:在函数‘init_threads()’中:
source.cpp:(.text+0x417):对‘pthread_create’未定义的引用
source.cpp:(.text+0x431):对‘pthread_join’未定义的引用
source.cpp:(.text+0x45c):对‘pthread_create’未定义的引用
source.cpp:(.text+0x476):对‘pthread_join’未定义的引用
collect2: 错误: ld 返回 1
后来查了半天发现是链接器要加上参数 -pthread
记录一下,说不定以后又忘了呢。。~

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.