cmake的一个编译报错

在一台新搭建的服务器上执行cmake的时候,报了如下错误:

$ cmake ./
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/bin/cc" is not able to compile a simple test program.

It fails with the following output:

...

查看下gcc与g++的版本:

$ gcc --version
gcc (GCC) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
g++ (GCC) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

发现都是5.1.0,那为何会有这行“The CXX compiler identification is GNU 4.4.7”报错呢?

查看当前目录下的CMakeCache.txt

发现如下两行配置:

//CXX compiler.
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++

//C compiler.
CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc

执行 /usr/bin/c++ --version 和 /usr/bin/cc --version,发现输出的版本号仍然是5.1.0,这就有点莫名其妙了。

google搜索出了一个github issue:https://github.com/Kingsford-Group/genesum/issues/2,在里面找到了解决方案:

cmake -DCMAKE_CXX_COMPILER=$(which g++) -DCMAKE_C_COMPILER=$(which gcc) ./

执行之后果然可以了,并且重新打开了CMakeCache.txt之后发现,编译器的两个选项改变了:

//CXX compiler.
CMAKE_CXX_COMPILER:FILEPATH=/usr/local/bin/g++

//C compiler.
CMAKE_C_COMPILER:FILEPATH=/usr/local/bin/gcc

这两个路径与命令 which gcc 和 which g++的输出一致。

猜测手动改CMakeCache.txt 的这两项应该也可以解决问题,比较困惑的就是,为何运行/usr/bin/c++ --version得到的版本号仍然是5.1.0?

这个疑惑要留待以后来解决了。
原文链接: https://www.cnblogs.com/minglee/p/9016306.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/273645

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月14日 下午11:45
下一篇 2023年2月14日 下午11:46

相关推荐