为什么我在 VSCode 中使用 SFML 总是得到未定义的引用?

Why do I keep getting undefined reference using SFML in VSCode?

我尝试编译从 sfml 教程中复制的这个程序

#include <SFML/Graphics.hpp>

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        // window.draw(...);

        // end the current frame
        window.display();
    }

    return 0;
}

使用以下 tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "g++",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\${fileBasenameNoExtension}.exe",
                "-ID:\Personal\SFML\include",
                "-LD:\Personal\SFML\lib",
                "-lsfml-graphics",
                "-lsfml-window",
                "-lsfml-system",
                "-lsfml-network"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "C:\MinGW\bin\g++.exe"
        }
    ]
}

但每次我这样做时,它都会为包含 sfml 内容的每一行显示“未定义的引用”错误。

g++ -g "D:\Prog 2\SC2\sc.cpp" -o "D:\Prog 2\SC2\sc.exe" -ID:\Personal\SFML\include -LD:\Personal\SFML\lib -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\pwucn\AppData\Local\Temp\ccERIoYa.o: in function `main':
D:/Prog 2/SC2/sc.cpp:6: undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:6: undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:6: undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:9: undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:13: undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:17: undefined reference to `_imp___ZN2sf6Window5closeEv'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:21: undefined reference to `_imp___ZN2sf5Color5BlackE'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:21: undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:27: undefined reference to `_imp___ZN2sf6Window7displayEv'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:6: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:/Prog 2/SC2/sc.cpp:6: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
collect2.exe: error: ld returned 1 exit status

即使我按照另一个 post 的建议将 dll 文件包含到项目中,这种情况仍然会发生。我做错了什么吗?

原来我弄错了 SFML 版本。现在可以正常使用了,谢谢!