Title

【实战】使用VSCode进行完整项目开发

士兵 类:

属性->姓名(许三多),枪

行为->开火、给枪装填子弹

枪 类:

属性->姓名(AK47),子弹数量

行为->发射子弹,装填子弹

 先设计枪类

(1)合理设计项目目录

(2)编写项目源文件

修改main.cpp也只会将修改过的main.cpp重新编译

(3)编写CMakeLists.txt

复制代码
cmake_minimum_required(VERSION 3.0)

project(SOLIDERFIRE)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

set(CMAKE_BUILD_TYPE Debug)

include_directories(${CMAKE_SOURCE_DIR}/include)

add_executable(my_cmake_exe main.cpp src/Gun.cpp src/Solider.cpp)
复制代码

(4)编写CMake项目

 

(5)配置json文件并调试项目

 create 啊 launch.json 选择 C++(GDB/LLDB)

 修改launch.json文件和tasks.json文件

program:代表需要debug的可执行文件所在位置

prelauchTask:代表在debug之前需要进行的task,卸载右边的task.json中,在build文件夹下进行cmake.. 和 make操作

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": [
        {
            "name": "g++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/my_cmake_exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
复制代码

tasks.json文件如下:

复制代码
{
    "version": "2.0.0",
    "options": {
        "cwd": "${workspaceFolder}/build"
    },
    "tasks": [
        {
            "type": "shell",
            "label": "cmake",
            "command": "cmake",
            "args": [
                ".."
            ]
        },
        {
            "label": "make",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "command": "make",
            "args": []
        },
        {
            "label": "Build",
            "dependsOrder": "sequence", // 按列出的顺序执行任务依赖项
            "dependsOn": [
                "cmake",
                "make"
            ]
        }
    ]
}
复制代码

调试

fn+F10 单步越过

fn+F11 单步进入

如果进入库函数,想退出来 shift+fn+F11

 

posted @   长大想当太空人  阅读(149)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· [翻译] 为什么 Tracebit 用 C# 开发
· 腾讯ima接入deepseek-r1,借用别人脑子用用成真了~
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?
· RFID实践——.NET IoT程序读取高频RFID卡/标签
点击右上角即可分享
微信分享提示