[英]VSCode : Images can't be opened when debugging(C++/SFML)
I am creating a little online game with SFML (C++). 我正在使用SFML(C ++)创建一个小型在线游戏。 My server is in C++ with SFML and my client is in C++ with SFML. 我的服务器是带有SFML的C ++,我的客户端是带有SFML的C ++。
My problem is quite simple, but I just can't find the answer on Google : 我的问题很简单,但是我在Google上找不到答案:
I am using images for my client. 我正在为客户使用图像。 I use the SFML functions to load images and it works fine when running the client normally, but when I use the GDB debugger with VScode, it does not load my images and I get this error for each images : 我使用SFML函数加载图像,并且在正常运行客户端时可以正常工作,但是当我将GDB调试器与VScode一起使用时,它不会加载图像,并且每个图像都会出现此错误:
Failed to load image "../myImage.png". 无法加载图片“ ../myImage.png”。 Reason: Unable to open file 原因:无法打开文件
Here is my debug configuration file : 这是我的调试配置文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/FarmersBuilds/farmers.launcher",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
And here is my build task file (everything works when running the executable generated with this without debugger) : 这是我的构建任务文件(运行没有调试器时生成的可执行文件,一切正常):
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "clientbuild",
"type": "shell",
"command": "cd FarmersBuilds/BuildObjects; g++ -g -c ../../main.cpp ../../GameScreen.cpp ../../LoginScreen.cpp ../../RegisterScreen.cpp ../../ResourceManager.cpp ../../RoomConnector.cpp ../../ScreenParameters.cpp; g++ -g main.o GameScreen.o LoginScreen.o RegisterScreen.o ResourceManager.o RoomConnector.o ScreenParameters.o -o ../farmers.launcher -lpthread -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network; ../farmers.launcher",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Here is an example of a constant I use to define the path of my files : 这是我用来定义文件路径的常量示例:
const std::string PATH_GRASS_FILE = "../grass.png";
Here is an example of how I load my images : 这是我如何加载图像的示例:
if (!loginScreenBackgroundTexture->loadFromFile(PATH_GRASS_FILE)) { ... }
Is there something I need to do to allow debugger to use my images or a paramater I must add in the debugger configuration file? 我需要做些什么来允许调试器使用我的映像,还是必须在调试器配置文件中添加的参数?
PS I am develeopping on Linux. PS我正在Linux上进行开发。
Thanks Cratebox99 谢谢Cratebox99
"command": "cd FarmersBuilds/BuildObjects; g++ -g -c ../../main.cpp ../../GameScreen.cpp ../../LoginScreen.cpp ../../RegisterScreen.cpp ../../ResourceManager.cpp ../../RoomConnector.cpp ../../ScreenParameters.cpp; g++ -g main.o GameScreen.o LoginScreen.o RegisterScreen.o ResourceManager.o RoomConnector.o ScreenParameters.o -o ../farmers.launcher -lpthread -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network; ../farmers.launcher",
The above line runs the executable from within the FarmersBuilds/BuildObjects
directory, which is then the Current Working Directory of the process. 上一行从FarmersBuilds/BuildObjects
目录中运行可执行文件,该目录随后是该进程的当前工作目录。 You probably want to cd ..; ./farmers.launcher
您可能想要cd ..; ./farmers.launcher
cd ..; ./farmers.launcher
instead. cd ..; ./farmers.launcher
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.