已解决:The C compiler identification is unknown

# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc
# whereis g++
g++: /usr/bin/g++  
# gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 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.

cmake:

rebuild
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):
  The CMAKE_C_COMPILER:

    /usr/local/bin/gcc

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:7 (project):
  The CMAKE_CXX_COMPILER:

    /usr/local/bin/c++

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

参考网上的做法:

sudo apt-get update
sudo apt-get install -y build-essential

无法解决。原因可能是gcc、g++的路径和cmake中使用的gcc、g++路径不一致。

# 指定gcc、g++的路径
cmake .. -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ ..

猜你喜欢

转载自blog.csdn.net/weixin_40437821/article/details/113856763