No CMAKE_CXX_COMPILER could be found.

错误信息

在使用cmake 编译 flex&bison程序时,使用cmake的project()指令,编译报以下错误,错误具体信息:

CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_CXX_COMPILER could be found.

  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.


-- Configuring incomplete, errors occurred!

原因是:cmake 的project() 命令在没有指定 LANGUAGES 选项时,默认是C和CXX(注意cmake 3.0之前的版本不支持LANGUAGES 关键字),CXX编译时需要指定 g++编译器。

解决方法

有2种方式:

方式一

在project() 命令中指定LANGUAGES 选项为C:

project(test1 LANGUAGES C)

方式二

安装g++ :

apt install g++

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注