欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

VSCode 在 macOS 下调试 C/C++ 失败(LLDB) - postcript

最编程 2024-03-01 22:12:52
...

其实,还有一种方法,使用另一种扩展(CodeLLDB)取代。
强力推荐:
首先安装扩展CodeLLDB:
在这里插入图片描述
然后依次配置好c_cpp_properties.json, tasks.json文件(建议手动配置,和上面一样);
后面就是最重要的不同之处:
1、点击创建
在这里插入图片描述
2、选择第二个(我们刚刚安装的扩张CodeLLDB)
在这里插入图片描述
3、生成的launch.json文件
在这里插入图片描述
4、很不幸,如果这时候你进行调试,就会报错:Internal debugger error: unable to find executable for '/Users/****/Doc/CplusWorkspace/<your program>
5、你需要把<your program>替换成你的编译程序的名字,显然,你每编译一个项目就要修改它显然不合适,所以我们想到了之前tasks.json里面有:

"args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],

所以把<your program>替换成${fileBasenameNoExtension}
附上最终的launch.json文件

{
    // 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": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
            "terminal": "external",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

写到这里,我之所以推荐该方法是因为方法1虽然解决了debug的问题,但本身还是有bug的。方法二就很完美了!
其实,我试错了很久才解决了该问题,主要是vscode这个编辑器真的很棒!有了他,我不需要sublime,不需要pycharm,不要要clion,不需要eclipse,哈哈哈!