I get an error when making a project with CMake:

-- Could NOT find Threads (missing:  Threads_FOUND)

The error log shows that CMake tripped up over something truly banal:

/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;}

This really should be no reason for CMake to think Threads doesn't exist. How do I go about fixing this?

share|improve this question
up vote 20 down vote accepted

I believe this is CMake bug 15058 which I just reported.

The test that CMake is using to check the include file uses an old-style C function definition. If -Wold-style-definition -Werror is in effect, gcc will barf on this.

I included a patch in the bug report linked above, but for a quick fix, find the file Modules/CheckIncludeFiles.cmake in your CMake installation (possibly in /usr/share/cmake or similar), find the line

  "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")

and change int main() to int main(void).

share|improve this answer
1  
This does get it to find the include file, but it doesn't seem like this is enough. Once I made the change and re-created it, I get this output. If however I have this in the CMakeLists.txt, then it works. It looks like it doesn't add -pthread itself? Yet I thought that's what it was supposed to do? – Claudiu Aug 5 '14 at 18:06
1  
@Claudiu: Huh. Have you checked the error log again? Maybe something else is wrong. – Nate Eldredge Aug 5 '14 at 18:15
1  
Yep, another warning treated as an error failure. "Check if compiler accepts -pthread" should be the only one that worked, I think, but it failed, log here. I fixed it by changing the offending line to printf("%p CC: %d\n", args, cc); – Claudiu Aug 5 '14 at 18:55
2  
I am getting this error an a fresh install of Ubuntu 16.04 and cmake 3.5. The CheckIncludeFiles.cmake already contains main(void). Building the same project on my 14.04 with cmake 2.8 that has main() does not give any error – Jana Jun 24 '16 at 23:04
1  
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.c‌​make:148 (message): Could NOT find Threads (missing: Threads_FOUND) Call Stack (most recent call first): /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.c‌​make:388 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.5/Modules/FindThreads.cmake:223 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) /usr/share/cmake-3.5/Modules/CMakeFindDependencyMacro.cmake:‌​65 (find_package) /usr/share/cmake-3.5/Modules/FindBoost.cmake:1338 (find_dependency) CMakeLists.txt:461 (find_package) – Jana Jun 27 '16 at 22:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.