试图将sfml和c ++与Windows 10上的可移植vscode链接

问题描述 投票:0回答:1

我正在Windows 10 64bit上工作,并且尝试使用Mingw-w64 / 32编译器将sfml 2.5.1链接到最新版本的vscode。我具有c / c ++扩展名,python扩展名,实时共享并安装了实时共享聊天。我把所有东西都放在USB闪存盘上,这样我就可以在任何地方处理我的项目。但是看来我无法正确链接sfml库。我进行了很多搜索,但我能找到的所有答案都是针对Code :: Blocks的,或者就是行不通。当您甚至由于链接问题而无法编写代码时,确实很烦人。

这里是我的main.cpp

#include <iostream>
#include <string>
#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();
    }
    std::cin.get();
    return 0;
}

我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "F:/Compiler/mingw32/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
}

我的tasks.json

 {
  "tasks": [
      {
      "type": "shell",
      "label": "build",
      "command": "F:/Compiler/mingw32/bin/g++.exe",
      "args": [
          "-Wall",
          "-Wextra",
          "-g",
          "${workspaceFolder}/main.cpp",
          "-I${workspaceFolder}/sources/SFML/include",
          "-L${workspaceFolder}/sources/SFML/lib",
          "-lsfml-audio",
          "-lsfml-graphics",
          "-lsfml-network",
          "-lsfml-system",
          "-lsfml-window"
      ],
      "options": {
          "cwd": "F:/Compiler/mingw32/bin"
      }
      }
  ],
  "version": "2.0.0"
}

和我的c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "F:/Compiler/mingw32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/**",
                "${workspaceFolder}/sources/SFML/include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "F:/Compiler/mingw32/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

出现错误:

Executing task: F:/Compiler/mingw32/bin/g++.exe -Wall -Wextra -g 
F:\Programmes\Projets\RPG/main.cpp - 
IF:\Programmes\Projets\RPG/sources/SFML/include - 
LF:\Programmes\Projets\RPG/sources/SFML/lib -lsfml-audio -lsfml-graphics - 
lsfml-network -lsfml-system -lsfml-window <

C:\Users\willy\AppData\Local\Temp\ccpyJSRW.o: In function `main':
F:/Programmes/Projets/RPG/main.cpp:7: undefined reference to 
`_imp___ZN2sf6StringC1EPKcRKSt6locale'
F:/Programmes/Projets/RPG/main.cpp:7: undefined reference to 
`_imp___ZN2sf9VideoModeC1Ejjj'
F:/Programmes/Projets/RPG/main.cpp:7: undefined reference to 
`_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15
ContextSettingsE'
F:/Programmes/Projets/RPG/main.cpp:8: undefined reference to 
`_imp___ZN2sf11CircleShapeC1Efj'
F:/Programmes/Projets/RPG/main.cpp:9: undefined reference to 
`_imp___ZN2sf5Color5GreenE'
F:/Programmes/Projets/RPG/main.cpp:9: undefined reference to 
`_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
F:/Programmes/Projets/RPG/main.cpp:11: undefined reference to 
`_imp___ZNK2sf6Window6isOpenEv'
F:/Programmes/Projets/RPG/main.cpp:14: undefined reference to 
`_imp___ZN2sf6Window9pollEventERNS_5EventE'
F:/Programmes/Projets/RPG/main.cpp:17: undefined reference to 
`_imp___ZN2sf6Window5closeEv'
F:/Programmes/Projets/RPG/main.cpp:20: undefined reference to 
`_imp___ZN2sf5ColorC1Ehhhh'
F:/Programmes/Projets/RPG/main.cpp:20: undefined reference to 
`_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
F:/Programmes/Projets/RPG/main.cpp:21: undefined reference to 
`_imp___ZN2sf12RenderStates7DefaultE'
F:/Programmes/Projets/RPG/main.cpp:21: undefined reference to 
`_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
F:/Programmes/Projets/RPG/main.cpp:22: undefined reference to 
`_imp___ZN2sf6Window7displayEv'
F:/Programmes/Projets/RPG/main.cpp:7: undefined reference to 
`_imp___ZN2sf12RenderWindowD1Ev'
F:/Programmes/Projets/RPG/main.cpp:7: undefined reference to 
`_imp___ZN2sf12RenderWindowD1Ev'
C:\Users\willy\AppData\Local\Temp\ccpyJSRW.o: In function 
`ZN2sf11CircleShapeD1Ev':
F:/Programmes/Projets/RPG/sources/SFML/include/SFML/Graphics/
CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
F:/Programmes/Projets/RPG/sources/SFML/include/SFML/Graphics/
CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
F:/Programmes/Projets/RPG/sources/SFML/include/SFML/Graphics/
CircleShape.hpp:41: undefined reference to `_imp___ZN2sf5ShapeD2Ev'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
c++ windows visual-studio-code sfml dynamic-linking
1个回答
1
投票

好的,所以基本上我只是下载了错误版本的SFML。我下载了SFML Visual C++ 15 (2017) - 32-bit,但我应该选的是SFML GCC 7.3.0 MinGW (DW2) - 32-bit。我还必须在tasks.json中精确定位我的.exe文件的名称:

"-o",
"${workspaceFolder}/a.exe",
© www.soinside.com 2019 - 2024. All rights reserved.