【发布时间】:2022-06-10 17:45:30
【问题描述】:
我找不到任何有效的方法,也不知道该去哪里。任务非常简单,只需将 SFML 作为库包含在我的 C++ 文件中,但每次尝试时,都会出现某种错误。我正在使用 SFML 的示例代码:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
这是我的 c_cpp_properties.json 文件:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\SFML-2.5.1\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\mingw64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
看起来很简单,但我就是不知道我做错了什么。我正在使用 MinGW 64 位和匹配的 SFML 版本。我在 VSCode 中使用 C/C++ 扩展和代码运行器等扩展进行编码(也尝试过手动编译)。我已将 MinGW64 和 SFML bin 路径添加到环境变量路径。我是 C++ 新手(早期的 Python)。
编辑
为了回答一些问题,该目录确实包含正确的文件,这就是我如此困惑的原因。我试图将\切换为/,但没有奏效:/。而错误(尴尬我忘了)是:
testing.cpp:1:10: fatal error: SFML/Graphics.hpp: No such file or directory
【问题讨论】:
-
首先想到:您的目录
C:\\SFML-2.5.1\\include是否有嵌套目录名为SFML,其中包含Graphics.hpp文件?第二个想法:尝试用包含路径中的/替换每个\\ -
您能否引用编译器错误消息而不改写“C++ 无法在#include (SFML) 中找到文件夹/文件”。
-
我认为您需要编辑 settings.json 和
code-runner.executorMap但我不使用代码运行器。此答案显示了如何添加其他 cpp 文件,而不是您可以为编译器添加包含路径:https://stackoverflow.com/a/57502607/487892
标签: c++ windows visual-studio-code sfml vscode-code-runner