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?

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

  • 相关阅读:
    解决MAMP启动mysql服务 但是Navicat连接不上
    iOS 更改状态栏颜色和隐藏状态栏
    Xcode 常用代码段
    iOS开发小技巧
    怎么让self.view的Y从navigationBar下面开始计算
    iOS强制横屏或强制竖屏
    判断当前viewcontroller是push还是present的方式显示的
    Git命令速查表
    全栈程序员的新玩具Rust(一) IDE环境
    火狐的野望
  • 原文地址:https://www.cnblogs.com/qiumingcheng/p/11146051.html
Copyright © 2011-2022 走看看