vscode配置cmake
1.安装c++扩展
2.配置c++编译环境
快捷键ctrl+shift+p,输入c++
编辑文件c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/c++/9",
"/usr/include/x86_64-linux-gnu/c++/9",
"/usr/include/c++/9/backward",
"/usr/lib/gcc/x86_64-linux-gnu/9/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/include/x86_64-linux-gnu/qt5"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "vector-of-bool.cmake-tools"
}
],
"version": 4
}
3.配置运行和调试
4.配置生成任务
打开main文件,终端->配置任务
编辑tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: /usr/bin/g++"
},
{
"type": "cmake",
"label": "CMake: 配置",
"command": "configure",
"problemMatcher": [],
"detail": "CMake 模板 配置 任务"
}
],
"version": "2.0.0"
}
5.配置c++代码风格
5.1clang-format
sudo apt-get install clang-format
下载vscode插件clang-format并配置为默认代码格式化器
5.2安装vs code的 clang-format扩展插件
5.3编辑settings.json
ctrl+shift+p,选择工作区设置
边界
{
"files.associations": {
"qtextcodec": "cpp",
"qapplication": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"strstream": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"bit": "cpp",
"*.inc": "cpp",
"ref_ptr": "cpp",
"viewer": "cpp",
"osgqopenglwidget": "cpp",
"graphicswindowqt": "cpp",
"compositeviewer": "cpp",
"graphicswindow": "cpp",
"keystone": "cpp",
"scene": "cpp",
"view": "cpp",
"viewerbase": "cpp",
"viewereventhandlers": "cpp",
"light": "cpp",
"stateset": "cpp",
"readfile": "cpp",
"intersectionvisitor": "cpp",
"export": "cpp",
"cullsettings": "cpp",
"referenced": "cpp",
"lod": "cpp",
"pagedlod": "cpp",
"dynamiclibrary": "cpp",
"node": "cpp",
"vec3d": "cpp",
"vec3f": "cpp",
"math": "cpp",
"geometry": "cpp",
"vec4": "cpp",
"group": "cpp",
"keyswitchmatrixmanipulator": "cpp",
"point": "cpp",
"primitiveset": "cpp",
"geode": "cpp",
"object": "cpp",
"vec4f": "cpp",
"types": "cpp",
"shape": "cpp",
"drawable": "cpp",
"graphicscontext": "cpp",
"quat": "cpp",
"vec2b": "cpp",
"vec2d": "cpp",
"vec2f": "cpp",
"vec2i": "cpp",
"vec2s": "cpp",
"vec2ub": "cpp",
"vec2ui": "cpp",
"vec2us": "cpp",
"vec3b": "cpp",
"vec3i": "cpp",
"vec3s": "cpp",
"vec3ub": "cpp",
"vec3ui": "cpp",
"vec3us": "cpp",
"vec4b": "cpp",
"vec4d": "cpp",
"vec4i": "cpp",
"vec4s": "cpp",
"vec4ub": "cpp",
"vec4ui": "cpp",
"vec4us": "cpp",
"viewport": "cpp",
"guieventadapter": "cpp",
"stateattribute": "cpp",
"datatypes": "cpp",
"kdtree": "cpp",
"mixinvector": "cpp",
"fast_back_stack": "cpp"
},
"cmake.debugConfig": {
},
//主要是下面配置项
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format"
},
"clang-format.fallbackStyle": "Google",
"clang-format.language.c.style": "Google",
"clang-format.executable": "clang-format",
"clang-format.language.cpp.style": "Google",
"C_Cpp.autocompleteAddParentheses": true,
"C_Cpp.clang_format_style": "{ BasedOnStyle: Chromium, IndentWidth: 2, ColumnLimit: 200, AllowShortIfStatementsOnASingleLine: true, AllowShortLoopsOnASingleLine: true}"
}