zoukankan      html  css  js  c++  java
  • 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?

    这个疑惑要留待以后来解决了。

  • 相关阅读:
    Python学习 day01打卡
    Python变量常量及注释
    Python基础简介
    「ubuntu」sudo命令卡住
    「ubuntu」sudo无密码
    「ubuntu」Ubuntu Recovery模式下只读问题
    「ubuntu」在Ubuntu Server 16.04 LTS下安装VMware Tools(转)
    「mysql」设置utf8编码
    「hive」hive2.3.0配置derby
    「hadoop」log4j参考
  • 原文地址:https://www.cnblogs.com/minglee/p/9016306.html
Copyright © 2011-2022 走看看