我尝试在 macOS 上的 Visual Studio Code 中使用 SDL2 设置 OpenGL 项目,但遇到两个问题:
未找到 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
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 调试问题?
您在 VSCode 中使用 SDL2 设置 OpenGL 项目取得了良好进展,但有一些问题需要解决。
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
。
--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 扩展!