C++环境配置
本流程主要参考:官方文档
配置 tasks.json
task.json 的主要作用 配置 编译 的相关参数
配置方式:
- user setting:
shfit+commond+p => >Tasks:Open User Tasks - workspace setting:
shfit+commond+p => Tasks:Configure Task前提,没有设置 user
具体的配置文件如下,包含了第三方库的设置
{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version": "2.0.0","tasks": [{"type": "shell","label": "clang++ build active file","command": "/usr/bin/clang++","args": ["-std=c++17","-stdlib=libc++","-g","${workspaceFolder}/*.cpp","-o","${fileDirname}/${fileBasenameNoExtension}","-I", // 设置 include 头文件路径"${workspaceFolder}/include","-L", // 设置 lib 库路径"${workspaceFolder}/library","-l", // 设置 liblua.a 静态库"lua"],"options": {"cwd": "${workspaceFolder}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true}}]}
配置 launch.json
launch.json 主要作用 配置 调试的相关参数
配置方式:
user setting:
shfit+commond+p => Preferences:Open User Settings配置 launch```json “launch”: {"version": "0.2.0","configurations": [{"name": "clang++ - user","type": "cppdbg","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"stopAtEntry": true,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "lldb","preLaunchTask": "clang++ build active file" // 先通过 Task 编译成可执行二进制文件再调试},]
}, ```
workspace setting:
直接在 debug 页签下添加单独的launch.json
配置第三方库代码提示
配置方式:
user setting :
shfit+commond+p => Preferences:Open User Settings
json // 第三方库头文件位置设置 "C_Cpp.default.includePath": [ "${workspaceFolder}/include" ],workspace setting :
配置文件c_cpp_properties.jsonshfit+commond+p => C/C++: Edit Configurations (UI)
设置includePath属性- 补充 如果安装了 插件
C Clang Commond Adapter,需要再 setting 中配置第三方库头文件的位置json // C Clang Commond Adapter 插件设置第三方库头文件位置 "clang.cflags": [ "-I", "${workspaceRoot}/include" ], "clang.cxxflags": [ "-I", "${workspaceRoot}/include" ]
扩展
Cmake 工具可以取代 tasks.json 步骤
