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

 

posted @ 2016-09-09 11:09  jiu~  阅读(13225)  评论(0编辑  收藏  举报