linux 线程操作问题undefined reference to 'pthread_create'的解决办法(cmake)

问题原因:

pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a.

所以在使用pthread_create()创建线程时,需要链接该库。

1. 终端:问题解决:
在编译中要加 -pthread参数

 gcc thread.c -o thread -pthread

2. qt的cmake配置: 可以修改CMakeLists.txt:

Here is the right answer:

ADD_EXECUTABLE(your_executable ${source_files})

TARGET_LINK_LIBRARIES( your_executable
pthread
)

equivalent to

-pthread
原文地址:https://www.cnblogs.com/jiu0821/p/5855827.html