所以,我对编码还很陌生,所以请耐心等待。我运行了在 Visual Studio Code 中安装 SFML 的教程视频,但最终还是到了这一步。我尝试按照说明进行操作。安装 SFML、设置 MingW64 编译器、将 mingw64/bin 添加到我的系统路径并调整配置。但当我尝试运行它时,就会出现这种情况。从昨天开始几个小时以来我一直在努力遵守它。但我无法使用 IntelliSense 代码来正确定位 SFML 库。自昨天以来我看到的唯一区别是“包含
测试.cpp
#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": [
"${default}",
"C:/SFML-2.6.1/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "gnu++17",
"compilerArgs": ["-I C:/SFML-2.6.1/include/**"]
}
],
"version": 4
}
任务.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile SFML executable",
"command": "g++",
"args": [
"-o",
"${workspaceFolder}/test.exe",
"-IC:/SFML-2.6.1/include/",
"-LC:/SFML-2.6.1/lib/",
"${workspaceFolder}/test.cpp",
"-lsfml-graphics",
"-lsfml-window",
"-lsfml-system"
],
"group": {
"kind": "build",
"isDefault": true,
},
}
]
}
任务:在代码块中运行任务
* Executing task: C:\winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5\mingw32\bin\g++.exe -o C:\Users\Altheo\SMFL/test.exe -IC:/SFML-2.6.1/include/ -LC:/SFML-2.6.1/lib/ C:\Users\Altheo\SMFL/test.cpp -lsfml-graphics -lsfml-window -lsfml-system
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-graphics.a when searching for -lsfml-graphics
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib/\libsfml-graphics.a when searching for -lsfml-graphics
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-graphics.a when searching for -lsfml-graphics
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lsfml-graphics: No such file or directory
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-graphics.a when searching for -lsfml-graphics
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-window.a when searching for -lsfml-window
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib/\libsfml-window.a when searching for -lsfml-window
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-window.a when searching for -lsfml-window
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lsfml-window: No such file or directory
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-window.a when searching for -lsfml-window
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-system.a when searching for -lsfml-system
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib/\libsfml-system.a when searching for -lsfml-system
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-system.a when searching for -lsfml-system
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lsfml-system: No such file or directory
C:/winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: skipping incompatible C:/SFML-2.6.1/lib//libsfml-system.a when searching for -lsfml-system
collect2.exe: error: ld returned 1 exit status
* The terminal process "C:\winlibs-i686-posix-dwarf-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5\mingw32\bin\g++.exe '-o', 'C:\Users\Altheo\SMFL/test.exe', '-IC:/SFML-2.6.1/include/', '-LC:/SFML-2.6.1/lib/', 'C:\Users\Altheo\SMFL/test.cpp', '-lsfml-graphics', '-lsfml-window', '-lsfml-system'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
你的标题说
error, "SFML/Graphics.hpp: No such file or directory"
但在你最近的尝试中没有这样的错误。现在最大的错误就是这种错误
skipping incompatible C:/SFML-2.6.1/lib//libsfml-system.a when searching for -lsfml-system
这意味着您下载的库与您尝试的构建不兼容。造成这种情况的一个原因是,当您尝试进行 64 位构建(或反之亦然)时,您下载了 32 位库。
您使用MSYS2来安装编译器,MSYS2有一个名为
pacman
的工具可以安装东西。最简单的方法是使用 pacman
安装 SFML,这样您就可以保证获得正确的版本,并且 pacman
会将安装位置放置在适合您的编译器的位置。因此,我的建议是删除现有的 SFML 安装,阅读 pacman
,然后使用它来安装 SFML。完成后,调整 c_cpp_properties.json 和tasks.json 文件以查找新安装。