我正在遵循this教程,并且已经完成了第一步。当我使用gui版本尝试对其进行编译时,我遇到了一个问题:它无法从Visual Studio中检测到生成器。我重新安装了Visual Studio,并做了一个新项目,以确保已安装生成器。之后,我检查了是否检测到它。我输入了
cmake --help
进入控制台,并写道“ Visual Studio 15 2017 Win64”可用作生成器。但是当我将其设置为生成器时,我仍然遇到相同的错误。
这是错误消息:
CMake Error at CMakeLists.txt:3 (project):
Generator
Visual Studio 15 2017 Win64
could not find any instance of Visual Studio.
配置不完整,发生了错误!
这是“ cmake --help”命令的“生成器”部分
Generators
The following generators are available on this platform:
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
这是我的CMakeLists.txt:
cmake_minimum_required (VERSION 3.12)
project (Test)
set (TEST_VERSION_MAJOR 1)
set (TEST_VERSION_MINOR 0)
configure_file ("$E:/programming/workspace/C++/Excercise/CMakeStuff/Test1/src/TestConfig.h.in""$E:/programming/workspace/C++/Excercise/CMakeStuff/Test1/bin/TestConfig.h")
include_directories("$E:/programming/workspace/C++/Excercise/CMakeStuff/Test1/bin")
add_executable (Test main.cpp)
这是我的main.cpp:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "TestConfig.h"
int main (int argc, char *argv[]) {
if (argc < 2) {
fprintf(stdout,"%s Version %d.%d\n", argv[0], TEST_VERSION_MAJOR, TEST_VERSION_MINOR);
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n", inputValue, outputValue);
return 0;
}