Vscode配置模板文件(launch.json, tasks.json,CMakeLists.txt)

在配置launch.json和tasks.json时发生错误,主要由如下问题:

launch.json单独配置没有问题,但是取消"preLaunchTask": "build"注释后,配置tasks.json后报错:preLaunchTask"build"已终止,退出代码为-1

主要是由于tasks.json中"type": "cppbuild"的问题,改为"type": "shell"即可,如下给出launch.json和tasks.json配置的所有内容:

launch.json:

// launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/main",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/bin",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ 生成活动文件",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

tasks.json:

// tasks.json
{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++ 生成活动文件",
            "command": "cd ${workspaceFolder};mkdir build;cd build;cmake ..;make",
            "args": [
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

CMakeLists.txt:(标准CMakeLists例程)

cmake_minimum_required(VERSION 3.0)
 
project(main)
 
SET(CMAKE_BUILD_TYPE "Debug")
set( CMAKE_CXX_FLAGS "-std=c++11" )
set( EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin )

# include_directories("/usr/include/eigen3")

# find_package( Sophus REQUIRED )
# include_directories( ${Sophus_INCLUDE_DIRS} )

# find_package( OpenCV 3 REQUIRED )
# include_directories( ${OpenCV_INCLUDE_DIRS} )

# find_package( PCL REQUIRED COMPONENT common io )
# include_directories( ${PCL_INCLUDE_DIRS} )
# add_definitions( ${PCL_DEFINITIONS} )
 
add_executable(main src/main.cpp)
 
# target_link_libraries( main ${OpenCV_LIBS} )
# target_link_libraries( main ${Sophus_LIBRARIES} )
# target_link_libraries( main ${PCL_LIBRARIES} )

注意:

1.需要在工作目录创建一个build文件夹

2.工程的CMakeLists.txt文件中,生成的可执行文件名为main

3.进入到build文件夹编译工程,操作为:cd build;cmake ..;make

4.执行完上面三部操作,即可开始调试程序。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值