码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-09-09 11:48:28      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

问题原因:

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

 

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

标签:

原文地址:http://www.cnblogs.com/jiu0821/p/5855827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!