VSCode : 调试时无法打开图片(C++/SFML)

VSCode : Images can't be opened when debugging(C++/SFML)

我正在使用 SFML (C++) 创建一个小型在线游戏。我的服务器在 C++ 中使用 SFML,而我的客户端在 C++ 中使用 SFML。

我的问题很简单,但是我在 Google 上找不到答案:

我正在为我的客户使用图像。我使用 SFML 函数加载图像,当 运行 客户端正常时它工作正常,但是当我将 GDB 调试器与 VScode 一起使用时,它不会加载我的图像并且每个图像都会出现此错误:

Failed to load image "../myImage.png". Reason: Unable to open 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
                }
            ]
        }
    ]
}

这是我的构建任务文件(当 运行 使用此生成的可执行文件没有调试器时一切正常):

{
    // 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
            }
        }
    ]
}

这是我用来定义文件路径的常量示例:

const std::string PATH_GRASS_FILE = "../grass.png";

这是我如何加载图像的示例:

if (!loginScreenBackgroundTexture->loadFromFile(PATH_GRASS_FILE)) { ... }

我需要做些什么来允许调试器使用我的图像或我必须在调试器配置文件中添加的参数吗?

P.S。我正在开发 Linux.

谢谢 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",

以上行从 FarmersBuilds/BuildObjects 目录中运行可执行文件,该目录是进程的当前工作目录。您可能想 cd ..; ./farmers.launcher 代替。