godot4.2 + GDextension c++在 vs code 中断点调试配置

游戏开发中如果做不到自己编写的代码做断点调试,无不是瞎子摸象,特别是C++这么底层的语言。这2天开始在VS studio中折腾,一直折腾不出结果,几次想要放弃GODOT。最终今天在VS code中搞定了这断点调试C++代码。

在上一篇文章我已经做好了"GDextension" c++ 插件

在Godot 4.2中使用GDExtension方式制作C++插件

接下来就是讲解vs code断点调试的配置步骤

1、首先在vs code 中安装2个插件,

  1. 插件名"c/c++" 作者:Microsoft

2)插件名:"CodeLLDB" 作者 Vadim Chugunov。 这个就是用来做调试的插件

2、用VS code 打开文件夹的方式打开我们的项目工程,注意是根目录 "gdextension_cpp_example/"。如果提示需要创建工作区,我们不创建工作区。

3、在VS code中点运行,然后在点不搜索框中我们点一下,然后在下拉列表选择lldb他会报错提示如下

我们点击 "ok"按钮进入配置 "launch"文件

首次进入配置文件默认如下

复制代码
{
    // 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}/<executable file>",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

我们要做修改,改成如下

复制代码
{
    // 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",
            "preLaunchTask": "build",
            "name": "Debug",
            "program": "D:\\pro\\Godot_v4.2.2-stable_mono_win64\\Godot_v4.2.2-stable_mono_win64.exe",
            "args": ["--path","E:\\godotProject\\gdextension_cpp_example\\demo"],
            "cwd": "${workspaceFolder}"
        }
    ]
}

注意:1、program 这项的值是我们godot应用程序的路径,你要修改成自己的安装路径,注意后缀是.exe,然后要把"\",改成双斜杠"\\".

2、--path 路径是我们项目工程中godot工程的路径

4、当配置好上面文件,然后我们点击debug运行,它会再报错提示,我们没有配置task.json。

我们点击 "configure task"按钮,然后搜索框这里会提示,我们选择"create task.json file form template",然后再点击 "orthers" 这类型的任务。修改后的代码如下

复制代码
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "scons -j10 target=template_debug debug_symbols=yes"
        }
    ]
}

就3项设置,第三项中的 -j10, 就是开启10线程编译,如果你的电脑够好,可以开多点。

完:写好以上这2个配置文件,然后点debug 运行,就能自动启动godot游戏窗口,而且我们还能再自己的c++插件代码中打断点调试。现在总算是可以进入正常的游戏开发了。

相关推荐
清水迎朝阳15 小时前
客户端软件 — 用户统计方案
服务器·c++·客户端·用户统计
再卷也是菜16 小时前
C++17(下)
c++
alexwang21116 小时前
HDU 4348 详细题解
c++·算法·题解·hdu·主席树·可持久化数据结构·可持久化线段树
程序员zgh17 小时前
C++ 拷贝赋值运算符 详解
c语言·开发语言·c++
皓月斯语18 小时前
B2132 素数对
c++·算法·题解
星轨初途19 小时前
LeetCode 热题 100——day2 字母异位词分组
c++·算法·leetcode
笨鸟先飞的橘猫20 小时前
c++面向对象编程
开发语言·c++
啦啦啦啦啦zzzz20 小时前
设计模式:桥接模式和组合模式
c++·设计模式·组合模式·桥接模式
-森屿安年-20 小时前
647. 回文子串
c++·算法·动态规划
fpcc20 小时前
c++应用网络编程之十七WebSocket
网络·c++·websocket