在 Visual Studio Code 中使用 OpenGL 设置 SDL2

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

我尝试在 macOS 上的 Visual Studio Code 中使用 SDL2 设置 OpenGL 项目,但遇到两个问题:

  1. 未找到 SDL2 库: 即使我已经安装了 SDL2,Visual Studio Code 也无法找到 SDL2 库。如何配置它来查找 SDL2 文件?它在库导入中显示为红色,我曾经遇到过这个错误,实际上我已经修复了:

    错误:

    dyld[3406]: Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2 Referenced from: ... Reason: no LC_RPATH's found

  2. LLDB 出现 MI 错误: 当我尝试调试项目时,LLDB 给出机器接口驱动程序错误。解决此问题的正确配置是什么?

    错误:

    Starting: "/usr/bin/lldb" --interpreter=mi
    error: unknown option: --interpreter=mi
    Use 'lldb --help' for a complete list of options.
    "/usr/bin/lldb" exited with code 1 (0x1).
    

这是我的配置文件:

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-F/Library/Frameworks",
                "-framework", "SDL2",
                "-framework", "OpenGL",
                "-I/Library/Frameworks/SDL2.framework/Headers",
                "-Wl,-rpath,/Library/Frameworks"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug C++ File",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: clang++ build active file",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/lldb"
        }
    ]
}

如何确保 Visual Studio Code 正确链接并找到 SDL2 库?可能需要进行哪些配置更改才能解决 LLDB 调试问题?

visual-studio-code sdl-2 lldb
1个回答
0
投票

您在 VSCode 中使用 SDL2 设置 OpenGL 项目取得了良好进展,但有一些问题需要解决。

  1. 未找到 SDL2 库: VSCode 未检测到 SDL2 库,导致它们显示为带有红色错误下划线。要解决此问题,您需要编辑 C/C++ 配置 UI 文件。您可以通过从命令面板运行命令 C/C++:编辑配置 (UI) 来查看 C/C++ 配置 UI:

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Library/Frameworks/SDL2.framework/Headers"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}

确保 SDL2 库安装在

/Library/Frameworks

  1. LLDB 的 MI 错误: LLDB 返回与
    --interpreter=mi
    相关的错误,指示配置不匹配或已弃用的选项。
    --interpreter=mi
    选项不再是 LLDB 的一部分。有关更多详细信息,请参阅 lists.llvm.org。作为解决方法,请使用以下配置:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch C++ Program",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "C/C++: clang++ build active file",
            "stopAtEntry": false,
            "MIMode": "lldb"
        }
    ]
}

确保您还安装了 C/C++ VSCode 扩展!

© www.soinside.com 2019 - 2024. All rights reserved.