【问题标题】:VSCode : Images can't be opened when debugging(C++/SFML)VSCode:调试时无法打开图像(C++/SFML)
【发布时间】:2018-06-21 20:07:20
【问题描述】:

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

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

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

无法加载图像“../myImage.png”。原因:无法打开文件

这是我的调试配置文件:

{
    // 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)) { ... }

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

附:我正在 Linux 上开发。

谢谢 板条箱99

【问题讨论】:

    标签: c++ visual-studio-code sfml


    【解决方案1】:
            "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。

    【讨论】:

    • 太好了,谢谢!通过将我的常量路径从 ../grass.png 重命名为 Grass.png 并添加 cd .. 来修复; ./farmers.launcher 在我的构建命令末尾。
    猜你喜欢
    • 2021-06-26
    • 2019-07-03
    • 2019-07-18
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多