添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
$ gcc -o what what.c
/tmp/ccI6m52b.o: In function `main':
what.c:(.text+0x37): undefined reference to `pthread_create'
what.c:(.text+0x48): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
$ gcc -pthread -o what what.c
$ ./what
In the thread.

However, when I run cmake with the following bare-bones CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.6)
FIND_PACKAGE (Threads)

The output is:

-- Could NOT find Threads (missing:  Threads_FOUND)

What gives? Error log states:

/usr/bin/cc   -std=c11 -D_GNU_SOURCE   -Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Werror -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized -Wlogical-op -Wno-error=maybe-uninitialized -Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes -march=native    -o CMakeFiles/cmTryCompileExec2533162744.dir/CheckIncludeFiles.c.o   -c /mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:5:5: 
     error: function declaration isn’t a prototype [-Werror=strict-prototypes]
 int main(){return 0;}
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c: 
     In function ‘main’:
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:5:5: 
     error: old-style function definition [-Werror=old-style-definition]
cc1: all warnings being treated as errors
[...]
Source:
/* */
#include <pthread.h>
int main(){return 0;}
                @saiarcot895: That isn't my source, that's the source cmake generated to test whether pthread exists. How can I get cmake to change it?
– Claudiu
                Jul 17, 2014 at 22:56
                Is there a folder called CMakeModules, and if so, is there a FindThreads.cmake or similar? Also, are you sure CMakeLists.txt doesn't have that code?
– saiarcot895
                Jul 17, 2014 at 23:01
                There is CMakeModules in the build directory, but no FindThreads.cmake. There is FindThreads.cmake in a Modules folder from the place I installed CMake from. That file doesn't contain the source either, but it does have a line CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H)
– Claudiu
                Jul 17, 2014 at 23:10
                You also asked this at stackoverflow.com/questions/24813827/… where I have just posted an answer.
– Nate Eldredge
                Aug 5, 2014 at 3:11