gpt4 book ai didi

c++ - 尝试将 sfml 和 c++ 与 Windows 10 上的可移植 vscode 链接起来

转载 作者:行者123 更新时间:2023-11-30 04:43:06 26 4
gpt4 key购买 nike

我在 Windows 10 64 位上工作,我正在尝试使用 Mingw-w64/32 编译器将 sfml 2.5.1 链接到最新版本的 vscode。我有 c/c++ 扩展,python 扩展,live安装了共享和实时共享聊天。我把所有东西都放在我的 USB key 上,这样我就可以在任何地方处理我的项目。但似乎我无法正确链接 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.

最佳答案

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

"-o",
"${workspaceFolder}/a.exe",

关于c++ - 尝试将 sfml 和 c++ 与 Windows 10 上的可移植 vscode 链接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58462355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com