首页 > 编程语言 > 详细

(C++)VsCode+Cmake

时间:2020-12-10 13:23:59      阅读:48      评论:0      收藏:0      [点我收藏+]

(C++)VsCode+Cmake

插件

  • C/C++ IntelliSense :代码提示*

  • Chinese (Simplified) Language Pack for Visual Studio Code :中文界面*

  • CMAKE

  • CMake Tools

  1. 新建文件夹
  2. Ctrl+Shift+P 打开命令面板输入Cmake:Quick Start
  3. 选择Kit,就是选择你用哪套编译工具,如果没有显示自动检测到的编译工具链
  4. 选择是生成库还是执行文件
  5. 配置调试文件,点击调试F5-启动调试,选择C++
  6. 配置 c_cpp_properties.json
{
 "configurations": [
  {
   "name": "CMake",
   "includePath": [
    "${workspaceFolder}/**"
   ],
   "defines": [
    "_DEBUG",
    "UNICODE",
    "_UNICODE"
   ],
   "windowsSdkVersion": "10.0.18362.0",
   "compilerPath": "/usr/bin/g++", // 根据自己的安装目录确定
   "cStandard": "c11",
   "cppStandard": "c++17",
   "intelliSenseMode": "gcc-x64", // 注意修改, 提供智能提示
   "configurationProvider": "vector-of-bool.cmake-tools"
  }
 ],
 "version": 4
}
  1. CMakeList.txt
cmake_minimum_required(VERSION 3.0.0)
project(cc_test VERSION 0.1.0)
aux_source_directory(. DIR_TOOT_SRCS)
# debug 模式
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
add_executable(cc_test ${DIR_TOOT_SRCS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}
  1. 编辑launch.json tasks.json,更改program参数
{
 "tasks": [
  {
   "type": "shell",
   "label": "cmake build active file", // 任务名称
   "command": "cmake --build ${workspaceFolder}/build --config Debug --target all -- -j 10", // cmake指令
   "args": [
   ], // 指令参数
   "options": {
    "cwd": "/usr/bin"
   }
  }
 ],
 "version": "2.0.0"
}
{
 // 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": "(gdb) Launch", // default: g++.exe build and debug active file
   "type": "cppdbg",
   "request": "launch",
   "program": "${workspaceFolder}/build/cc_test", // 可执行文件所在的路径, cc_test= 替换成自己的项
   "args": [],
   "stopAtEntry": false,
   "cwd": "${workspaceFolder}",
   "environment": [],
   "externalConsole": true, // 显示独立控制台窗口
   "MIMode": "gdb",
   "miDebuggerPath": "/usr/bin/gdb",
   "setupCommands": [
    {
     "description": "Enable pretty-printing for gdb",
     "text": "-enable-pretty-printing",
     "ignoreFailures": true
    }
   ],
   "preLaunchTask": "cmake build active file" // 执行cmake编译任务, 再task.json中定义的
  }
 ]
}

一键分号;

keybindings.json
[
    {
        "key": "ctrl+;",
        "command": "macros.end_semicolon"   
    },
]
    
settings.json    
{"macros": {
    "end_semicolon": [ // 末尾加分号
        "cursorLineEnd",
        {
            "command": "type",
            "args": {
                "text": ";"
            }
        },
    ],

    }
}

(C++)VsCode+Cmake

原文:https://www.cnblogs.com/haoge2000/p/14113446.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!