我的系统中安装了 ubuntu 11。我有一个使用 pthread 库的 c 程序。
我收到错误 Undefined reference to sem_wait()
即使我使用标志 -lpthread
编译。
例如:
gcc -lpthread prog.c
该程序在其他 ubuntu 安装上运行良好。
最佳答案
尝试:
gcc -pthread
而不是 -lpthread
。我相信,差异是显着的。后者链接到 libpthread
,前者链接到 libpthread 和其他一些东西!
sem_wait
是 librt 的一部分,因此您也可以使用 gcc -lrt
,但是 -pthread
会为您完成此操作(并且其他一切也一样!)。
关于c++ - gcc -lpthread 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8264701/