繁体   English   中英

使用-lpthread,g ++编译器错误,“未定义引用”信号量调用,例如`sem_open'

[英]with -lpthread, g++ compiler error, “undefined reference to ” semaphore calls such as `sem_open'

我是posix线程库的新手,我尝试从教程中编译示例代码:

g++ -lpthread agreement.cpp -o agreement

但是我无法编译代码并收到以下错误消息:

a3q2.cpp:(.text+0x7e): undefined reference to `sem_open'
a3q2.cpp:(.text+0xab): undefined reference to `sem_wait'
a3q2.cpp:(.text+0x290): undefined reference to `sem_post'
a3q2.cpp:(.text+0x2af): undefined reference to `sem_close'
a3q2.cpp:(.text+0x2bb): undefined reference to `sem_unlink'
collect2: ld returned 1 exit status
make: *** [a3q2_exe] Error 1

我知道编译工作需要-lpthread,但是我可能还需要其他任何选项才能解决问题吗? 如果不是我如何安装“正确的”pthread库?

谢谢你的帮助!

你想要编译选项-pthread (如果你真的使用pthreads)。 如果你只需要那些他们在功能librt所以用-lrt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM