「linux」解决No CMAKE_C_COMPILER could be found

问题描述

关键报错如下

1
2
3
4
5
6
7
8
9
10
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:13 (project):
No CMAKE_C_COMPILER could be found.

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.
...
...
make: *** No targets specified and no makefile found. Stop.

提示找不到C/CXX compiler路径,搜了一下似乎常见于Visual studio问题,并找到方法多为以下1,2两种

解决方案

  1. 安装build-essential
    1
    $ sudo apt-get install build-essential 
  2. 安装g++
    1
    $ sudo apt-get install g++
  3. 手动添加路径
    若二者均已安装仍报错,那么找到gcc位置,手动添加下路径即可
    1
    2
    3
    $ whereis gcc
    gcc: /usr/bin/gcc /usr/lib/gcc
    $ export CC=/usr/bin/gcc # 视上一行输出填写路径

再次编译应该就能顺利完成了.

参考链接