我是 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 库?
谢谢你的帮助!