vscode 配置 c/c++
[!CAUTION]
使用本文的配置需要预装
cmake
,msvc
,拥有cmake
、CMake Tools
插件
工程目录
D:.
│ CMakeLists.txt
│
├─.vscode
│ CMakePresets.json
│ c_cpp_properties.json
│
└─code
│ main.cpp
│
└─head
test.h
编写初始配置文件
配置 CMake Presets
该文件用来管理构建配置
CMakePresets.json
{
"version": 3,
"configurePresets": [
{
"name": "default",
"hidden": false,
"generator": "msvc",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
}
]
}
配置 c_cpp_properties.json
启动自动补全功能
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx86/x86/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x86"
}
],
"version": 4
}
编写源代码
该部分省略
编写CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
# 设置项目名称
project(HelloWorld)
INCLUDE_DIRECTORIES(../src/head)
# 添加可执行文件
add_executable(HelloWorld ../src/code/test.cpp)
运行 CMake 配置
按下ctrl+shift+p
,输入CMake: Configure
,初始化配置
编译运行
使用cmake命令
标签:CMake,vscode,配置,c++,json,cpp From: https://www.cnblogs.com/jarico/p/18442011