cmake 编译后无明显错误,但提示找不到 pthread

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
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值