Linux编译错误:对‘sem_init/sem_wait/sem_destroy’等未定义的引用

[root@init1 youshuang]# g++ main.cpp http_conn.cpp -o main

出现如下报错:

/tmp/cccJr4yJ.o:在函数‘sem::sem()’中:
main.cpp:(.text._ZN3semC2Ev[_ZN3semC5Ev]+0x1f): 对‘sem_init’未定义的引用
/tmp/cccJr4yJ.o:在函数‘sem::~sem()’中:
main.cpp:(.text._ZN3semD2Ev[_ZN3semD5Ev]+0x14): 对‘sem_destroy’未定义的引用
/tmp/cccJr4yJ.o:在函数‘sem::wait()’中:
main.cpp:(.text._ZN3sem4waitEv[_ZN3sem4waitEv]+0x14): 对‘sem_wait’未定义的引用
/tmp/cccJr4yJ.o:在函数‘sem::post()’中:

main.cpp:(.text._ZN3sem4postEv[_ZN3sem4postEv]+0x14):对‘sem_post’未定义的引用

解决办法:编译的时候加 -pthread 即可。

[root@init1 youshuang]# g++ -pthread main.cpp http_conn.cpp -o main

猜你喜欢

转载自blog.csdn.net/mijichui2153/article/details/80952321
sem