关于利用cmake进行ipmctl安装出现/usr/bin/ld: cannot find -lpthreads错误提示(补充)

关于ipmctl的安装以及遇坑,已有文章讲的很详细了(见https://blog.csdn.net/SweeNeil/article/details/89841813)

此处补充一下在我用cmake3.1.5安装ipmctl遇到错误提示的一个解决办法:此处贴出从stackoverflow里找的相似报错提示:

File /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include 

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_e693b/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_e693b.dir/build.make CMakeFiles/cmTC_e693b.dir/build
gmake[1]: Entering directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o   -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTC_e693b
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e693b.dir/link.txt --verbose=1
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o  -o cmTC_e693b -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld outputs 1
CMakeFiles/cmTC_e693b.dir/build.make:97: recipe for target 'cmTC_e693b' failed
gmake[1]: Leaving directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_e693b/fast' failed
gmake[1]: *** [cmTC_e693b] Error 1
gmake: *** [cmTC_e693b/fast] Error 2

该提示出现在CMakeFile/CMakeEorror.log,注意提示中的

/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o  -o cmTC_e693b -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads

甚至有时候还会同时出现下图类似的找不到pthread_create的情况

Looking for pthread_create -- Looking for pthread_create - not found 
 undefined reference to symbol 'pthread_create

但是经过实验会发现手动测试该目录下自己编写的-lpthread程序调用pthread_create函数没有报错,正常运行。(如果自己测试的也找不到,则可能是没有下载对应libpthread库或者没有配置环境变量,解决方法自行查阅),经过搜索发现有人说这是cmake低版本的bug,需要一句部分cmake源码,具体查看https://www.e-learn.cn/content/wangluowenzhang/153721。

但是我实验之后依然无效,最后更新了cmake从3.1.5到3.15,发现问题解决了。

可见cmake的Eorror.log报错不一定是准确的。log日志全程都是关于pthread库的前后矛盾的报错,但实际问题是cmake本身需要更新(有时候甚至是因为缺少一些必要库而导致报错pthread链接错误)。更新软件有时候是最有效的解决办法。

你可能感兴趣的:(linux环境搭建)