我使用pthread创建了线程池。 当我尝试pthread_create时,得到以下信息:
[ 25%] Building C object CMakeFiles/ex4.dir/threadPool.c.o
[ 50%] Building C object CMakeFiles/ex4.dir/test.c.o
[ 75%] Linking C executable ex4
CMakeFiles/ex4.dir/threadPool.c.o: In function `tpCreate':
/home/user2/CLionProjects/ex4/threadPool.c:54: undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/ex4.dir/build.make:113: recipe for target 'ex4' failed
make[3]: *** [ex4] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/ex4.dir/all' failed
make[2]: *** [CMakeFiles/ex4.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/ex4.dir/rule' failed
make[1]: *** [CMakeFiles/ex4.dir/rule] Error 2
Makefile:118: recipe for target 'ex4' failed
make: *** [ex4] Error 2
我试图添加SET(CMAKE_C_FLAGS -lpthread),但是没有用。 我尝试通过终端进行编译,但同样失败。 有什么建议吗?