Ubuntu 下使用Visual Studio Code 与 CMakeLists进行C++代码编译

Ubuntu 下使用Visual Studio Code 与 CMakeLists进行C++代码编译

  • 1、通过下述语句生成CMakeLists环境下所需要的3个json文件
  • 2、c_cpp_properties.json
  • 3、launch.json
  • 4、tasks.json

1、通过下述语句生成CMakeLists环境下所需要的3个json文件

参考资料:VSCode 安装使用和配置CMake工程
链接: https://www.jianshu.com/p/6369cbd14528.

(1)使用【Ctrl+Shift+p】,输入C/Cpp:Edit Configurations生成配置文件 c_cpp_properties.json

(2)使用【Ctrl+Shift+p】,输入Tasks: Configure task生成配置文件 tasks.json

(3)使用【Ctrl+Shift+p】,输入Open launch.json生成配置文件launch.json

2、c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include",
                "/usr/local/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

3、launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/useGeometry/build/eigenMatrix",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/useGeometry",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "make build"
        }
    ]
}

4、tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make build",
            "type": "shell",
            "command": "cd ./build ;cmake ../ ;make",//编译命令
            "group": { 
                "kind": "build", 
                "isDefault": true
            }
        },
        { 
            "label": "clean", 
            "type": "shell", 
            "command": "make clean"
        }
    ]
}

你可能感兴趣的:(编程基础)