在VScode中借用CMake指令Debug PCL代码

在VScode中借用CMake指令Debug PCL代码

在Ubuntu18.04中,借用VScode对PCL代码进行Debug

在直接使用g++编译PCL时会一直显示无法搜索到某些库,故借用Cmake指令生成可执行文件之后在用VScode进行Debug

1.CMakeLiset.txt 文件的编写

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(my_main) // 项目的名字

find_package(PCL 1.8 REQUIRED) //使用pcl-1.8版本

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

set(CMAKE_BUILD_TYPE "Debug") //设置生成的可执行文件可以进行Debug操作,一定要写!!

add_executable(my_main my_main.cpp my_head.h my_head.cpp)
target_link_libraries (my_main ${PCL_LIBRARIES})

2.task.json 文件的编写

{
    "version": "2.0.0",
    "tasks": [
        {
            //在这这之前,提前创建一个名字叫Build的文件夹
            "label": "build",//编译的项目名,build
            "type": "shell",
            "command": "cd ./build ;cmake .. ;make",//编译命令
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "clean",
            "type": "shell",
            "command": "make clean",
        }
    ]
}

3.launch.json 文件编写

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "preLaunchTask": "cmakebuild",//若不需要重复编译,则去掉这个,可以加快代码debug速度
            "program": "${workspaceFolder}/build/my_main",//注意这里地址,别偷偷藏了个空格
            "args": ["1.pcd"], //这里存放主函数需要传递的参数
            "stopAtEntry": true,//表示设置断点
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//若不想每次debug都产生一个新的终端,就把这个改称false
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

以上3个VScode是最基本的配置,如果还需要实现其他的功能,可以在对应的文件上进行改善。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值