A compilation error of cmake

When executing cmake on a newly built server, the following error was reported:

$ 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:

...

Check out the versions of gcc and 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.

It is found that they are all 5.1.0, so why is there an error in the line "The CXX compiler identification is GNU 4.4.7"?

View CMakeCache.txt in the current directory

The following two lines of configuration are found:

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

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

Execute /usr/bin/c++ --version and /usr/bin/cc --version, and find that the output version number is still 5.1.0, which is a bit baffling.

Google searched for a github issue: https://github.com/Kingsford-Group/genesum/issues/2, and found a solution in it:

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

After execution, it is OK, and after reopening CMakeCache.txt, I found that the two options of the compiler have changed:

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

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

These two paths are consistent with the output of the commands which gcc and which g++.

Guessing that manually changing these two items of CMakeCache.txt should also solve the problem. What is more confusing is why the version number obtained by running /usr/bin/c++ --version is still 5.1.0?

This doubt is left to be resolved later.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326607811&siteId=291194637