• 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?

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

  • 相关阅读:
    Error Domain=com.google.greenhouse Code=-102
    给分类(Category)添加属性
    Eclipse 4.4(luna) 安装Veloeclipse 2.0.8时报错的问题
    MAVEN常用命令
    Redis之七种武器
    Redis系统性介绍
    Nginx、LVS及HAProxy负载均衡软件的优缺点详解
    Redis介绍以及安装(Linux)
    MYSQL + MHA +keepalive + VIP安装配置(三)--keepalived安装配置
    MYSQL + MHA +keepalive + VIP安装配置(二)--MHA的配置
  • 原文地址:https://www.cnblogs.com/minglee/p/9016306.html
Copyright © 2020-2023  润新知