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?

這個疑惑要留待以后來解決了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM