为 VScode 配置 CMake raylib-cpp
Configuring CMake raylib-cpp for VScode
我已经在 VSCode 和 Notepad++ 中成功安装了 raylib 和 运行 示例 .c 文件。
我正在尝试执行此存储库中的文件 raylib-cpp/projects/CMake
我没有直接从 VSCoode 更改 repo 和 运行 cmake 命令中的文件。
main.cpp
#include "raylib-cpp.hpp"
int main()
{
int screenWidth = 800;
int screenHeight = 450;
raylib::Color background(RAYWHITE);
raylib::Color textColor(LIGHTGRAY);
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
while (!w.ShouldClose())
{
BeginDrawing();
background.ClearBackground();
textColor.DrawText("Success!", 190, 200, 20);
EndDrawing();
}
return 0;
}
我尝试了 运行 这个 git 集线器仓库中指示的命令:raylib-CMake-example 但是当我从 运行 make
命令时出现错误44=] bash 在 build
文件夹中,我也尝试了 mingw32-make
但它没有用。然后
我在 VSCode
中安装了 CMake 工具扩展
和 运行 来自扩展的构建命令,但出现错误说明:
inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
我正在使用 Visual Studio Build Tools 2017 Release-amd64
作为工具包。
当我尝试 运行 来自 raylib 的示例 .c 文件时,我不得不将 opengl 版本从 33 更改为 21 以使 window 正常工作。
我的文件夹如下所示:
输出日志如下所示:\
[main] Building folder: Game2CPP raylib-cpp-example
[build] Starting build
[proc] Executing command: F:\Code\CPP\Raylib\cmake-3.18.2-win64-x64\bin\cmake.EXE --build f:/Code/CPP/Raylib/TestGames/Game2CPP/build --config Debug --target raylib-cpp-example -- /maxcpucount:6
[build] Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build]
[build] glfw_objlib.vcxproj -> F:\Code\CPP\Raylib\TestGames\Game2CPP\build\_deps\raylib-build\src\external\glfw\src\glfw_objlib.dir\Debug\glfw_objlib.lib
[build] glfw.vcxproj -> F:\Code\CPP\Raylib\TestGames\Game2CPP\build\_deps\raylib-build\src\external\glfw\src\Debug\glfw3.lib
[build] raylib_static.vcxproj -> F:\Code\CPP\Raylib\TestGames\Game2CPP\build\_deps\raylib-build\src\Debug\raylib_static.lib
[build] main.cpp
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(206): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(207): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(208): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(209): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(210): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(211): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(212): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(213): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(214): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(215): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(216): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(217): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(218): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(219): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(220): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(221): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(222): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(223): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(224): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(225): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(226): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(227): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(228): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(229): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(230): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(231): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[build] Build finished with exit code 1
我看到已经报告了一个问题 https://github.com/RobLoach/raylib-cpp/issues/51。我猜作者的默认 C++ 编译器标准设置为 17,因此他的机器上没有问题。然而,你落后了一步。正如您的编译器所建议的那样,内联变量自 C++17 起可用。看来您使用的是一些较旧的标准(但不确定是哪个)。不确定哪个是 visual studio 的 cpp 编译器的默认编译器。
您可以像这样通过 CMake 为您的项目设置 C++ 标准:
set_property(TARGET tgt PROPERTY CXX_STANDARD 11)
考虑到这个库似乎是 'header-only',您可以将 CXX_STANDARD 设置为 17 仅用于您的可执行文件。但是,如果该 raylib 库有一些对象,您必须在 https://github.com/RobLoach/raylib-cpp/blob/master/projects/CMake/CMakeLists.txt 中为 raylib-cpp-example
目标将 CXX_STANDARD 设置为 17。
我已经在 VSCode 和 Notepad++ 中成功安装了 raylib 和 运行 示例 .c 文件。
我正在尝试执行此存储库中的文件 raylib-cpp/projects/CMake
我没有直接从 VSCoode 更改 repo 和 运行 cmake 命令中的文件。
main.cpp
#include "raylib-cpp.hpp"
int main()
{
int screenWidth = 800;
int screenHeight = 450;
raylib::Color background(RAYWHITE);
raylib::Color textColor(LIGHTGRAY);
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
while (!w.ShouldClose())
{
BeginDrawing();
background.ClearBackground();
textColor.DrawText("Success!", 190, 200, 20);
EndDrawing();
}
return 0;
}
我尝试了 运行 这个 git 集线器仓库中指示的命令:raylib-CMake-example 但是当我从 运行 make
命令时出现错误44=] bash 在 build
文件夹中,我也尝试了 mingw32-make
但它没有用。然后
我在 VSCode
中安装了 CMake 工具扩展
和 运行 来自扩展的构建命令,但出现错误说明:
inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
我正在使用 Visual Studio Build Tools 2017 Release-amd64
作为工具包。
当我尝试 运行 来自 raylib 的示例 .c 文件时,我不得不将 opengl 版本从 33 更改为 21 以使 window 正常工作。
我的文件夹如下所示:
输出日志如下所示:\
[main] Building folder: Game2CPP raylib-cpp-example
[build] Starting build
[proc] Executing command: F:\Code\CPP\Raylib\cmake-3.18.2-win64-x64\bin\cmake.EXE --build f:/Code/CPP/Raylib/TestGames/Game2CPP/build --config Debug --target raylib-cpp-example -- /maxcpucount:6
[build] Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build]
[build] glfw_objlib.vcxproj -> F:\Code\CPP\Raylib\TestGames\Game2CPP\build\_deps\raylib-build\src\external\glfw\src\glfw_objlib.dir\Debug\glfw_objlib.lib
[build] glfw.vcxproj -> F:\Code\CPP\Raylib\TestGames\Game2CPP\build\_deps\raylib-build\src\external\glfw\src\Debug\glfw3.lib
[build] raylib_static.vcxproj -> F:\Code\CPP\Raylib\TestGames\Game2CPP\build\_deps\raylib-build\src\Debug\raylib_static.lib
[build] main.cpp
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(206): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(207): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(208): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(209): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(210): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(211): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(212): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(213): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(214): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(215): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(216): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(217): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(218): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(219): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(220): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(221): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(222): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(223): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(224): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(225): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(226): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(227): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(228): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(229): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(230): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[build] f:\code\cpp\raylib\testgames\game2cpp\build\_deps\raylib-cpp-src\include\./Color.hpp(231): error C7525: inline variables require at least '/std:c++17' [F:\Code\CPP\Raylib\TestGames\Game2CPP\build\raylib-cpp-example.vcxproj]
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[build] Build finished with exit code 1
我看到已经报告了一个问题 https://github.com/RobLoach/raylib-cpp/issues/51。我猜作者的默认 C++ 编译器标准设置为 17,因此他的机器上没有问题。然而,你落后了一步。正如您的编译器所建议的那样,内联变量自 C++17 起可用。看来您使用的是一些较旧的标准(但不确定是哪个)。不确定哪个是 visual studio 的 cpp 编译器的默认编译器。
您可以像这样通过 CMake 为您的项目设置 C++ 标准:
set_property(TARGET tgt PROPERTY CXX_STANDARD 11)
考虑到这个库似乎是 'header-only',您可以将 CXX_STANDARD 设置为 17 仅用于您的可执行文件。但是,如果该 raylib 库有一些对象,您必须在 https://github.com/RobLoach/raylib-cpp/blob/master/projects/CMake/CMakeLists.txt 中为 raylib-cpp-example
目标将 CXX_STANDARD 设置为 17。