CMAKE:“找不到 CMAKE_CXX_COMPILER。”

Sta*_*tec 6 c++ cmake

我有一个简单的项目,其中文件结构如下所示:

- CMakeLists.txt
- main.cpp
Run Code Online (Sandbox Code Playgroud)

看起来CMakeLists.txt像这样:

# Project initialization
cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial main.cpp)
Run Code Online (Sandbox Code Playgroud)

当我运行 Cmake GUI 时,我得到:

CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_CXX_COMPILER could be found.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我安装了 Microsoft Visual Studio 2017。我已经编译并运行了它的应用程序。CMAKE 教程中的基本示例不起作用。

谁能告诉我为什么?

小智 5

看到同样的错误 - 检测 C 编译功能 - 在 CMakeLists.txt:4 (PROJECT) 处完成 CMake 错误:找不到 CMAKE_CXX_COMPILER。

通过将环境变量“CXX”或 CMake 缓存条目 CMAKE_CXX_COMPILER 设置为编译器的完整路径或编译器名称(如果它位于 PATH 中),告诉 CMake 在哪里找到编译器。

-- 配置不完整,出现错误!

apt update
apt install build-essential
Run Code Online (Sandbox Code Playgroud)


Bow*_*ens 1

我不确定出了什么问题,但您可能想看看:

https://learn.microsoft.com/en-us/cpp/ide/cmake-tools-for-visual-cpp?view=vs-2017

Visual Studio 2017 能够直接打开 cmake 文件(应该在幕后为您执行生成器步骤),这可能会避免您遇到的问题。