cmake 构建工程,完成后,没有明显错误,但就是提示"Configuration failed"。
经过仔细检查,出错原因和"Error.log"提示完全没关系!
解决办法
:仔细检查刚修改过的CMakeLists.txt
,一定有调用出错
/少写内容
的地方
错误文件"Error.log"的错误类似下文:
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: ${projectDir}/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_c7717/fast && /usr/bin/make -f CMakeFiles/cmTC_c7717.dir/build.make CMakeFiles/cmTC_c7717.dir/build
make[1]: Entering directory '${projectDir}/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_c7717.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -O2 -DNDEBUG -g -fno-omit-frame-pointer -fPIE -o CMakeFiles/cmTC_c7717.dir/src.c.o -c ${projectDir}/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_c7717
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_c7717.dir/link.txt --verbose=1
/usr/bin/cc -O2 -DNDEBUG -g -fno-omit-frame-pointer CMakeFiles/cmTC_c7717.dir/src.c.o -o cmTC_c7717
CMakeFiles/cmTC_c7717.dir/src.c.o: In function `main':
${projectDir}/build/CMakeFiles/CMakeTmp/src.c:11: undefined reference to `pthread_create'
${projectDir}/build/CMakeFiles/CMakeTmp/src.c:12: undefined reference to `pthread_detach'
${projectDir}/build/CMakeFiles/CMakeTmp/src.c:13: undefined reference to `pthread_cancel'
${projectDir}/build/CMakeFiles/CMakeTmp/src.c:14: undefined reference to `pthread_join'
${projectDir}/build/CMakeFiles/CMakeTmp/src.c:15: undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_c7717.dir/build.make:105: recipe for target 'cmTC_c7717' failed
make[1]: *** [cmTC_c7717] Error 1
make[1]: Leaving directory '${projectDir}/build/CMakeFiles/CMakeTmp'
Makefile:140: recipe for target 'cmTC_c7717/fast' failed
make: *** [cmTC_c7717/fast] Error 2
Source file was:
#include <pthread.h>
static void* test_func(void* data)
{
return data;
}
int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_cancel(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);
return 0;
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: ${projectDir}/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_a697d/fast && /usr/bin/make -f CMakeFiles/cmTC_a697d.dir/build.make CMakeFiles/cmTC_a697d.dir/build
make[1]: Entering directory '${projectDir}/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_a697d.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -O2 -DNDEBUG -g -fno-omit-frame-pointer -fPIE -o CMakeFiles/cmTC_a697d.dir/CheckFunctionExists.c.o -c /usr/local/share/cmake-3.19/Modules/CheckFunctionExists.c
Linking C executable cmTC_a697d
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a697d.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -O2 -DNDEBUG -g -fno-omit-frame-pointer CMakeFiles/cmTC_a697d.dir/CheckFunctionExists.c.o -o cmTC_a697d -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_a697d.dir/build.make:105: recipe for target 'cmTC_a697d' failed
make[1]: *** [cmTC_a697d] Error 1
make[1]: Leaving directory '${projectDir}/build/CMakeFiles/CMakeTmp'
Makefile:140: recipe for target 'cmTC_a697d/fast' failed
make: *** [cmTC_a697d/fast] Error 2
Determining if the strtod_l exist failed with the following output:
Change Dir: ${projectDir}/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_da49d/fast && /usr/bin/make -f CMakeFiles/cmTC_da49d.dir/build.make CMakeFiles/cmTC_da49d.dir/build
make[1]: Entering directory '${projectDir}/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_da49d.dir/CheckSymbolExists.c.o
/usr/bin/cc -O2 -DNDEBUG -g -fno-omit-frame-pointer -fPIE -o CMakeFiles/cmTC_da49d.dir/CheckSymbolExists.c.o -c ${projectDir}/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
${projectDir}/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c: In function 'main':
${projectDir}/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: error: 'strtod_l' undeclared (first use in this function); did you mean 'strtoull'?
return ((int*)(&strtod_l))[argc];
^~~~~~~~
strtoull
${projectDir}/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: note: each undeclared identifier is reported only once for each function it appears in
CMakeFiles/cmTC_da49d.dir/build.make:84: recipe for target 'CMakeFiles/cmTC_da49d.dir/CheckSymbolExists.c.o' failed
make[1]: *** [CMakeFiles/cmTC_da49d.dir/CheckSymbolExists.c.o] Error 1
make[1]: Leaving directory '${projectDir}/build/CMakeFiles/CMakeTmp'
Makefile:140: recipe for target 'cmTC_da49d/fast' failed
make: *** [cmTC_da49d/fast] Error 2
File ${projectDir}/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <stdlib.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef strtod_l
return ((int*)(&strtod_l))[argc];
#else
(void)argc;
return 0;
#endif
}