每个人的电脑路径因人而异,下面只是我的配置,仅供参=参考。
vscode的安装以及插件软件的安装根据另一个博主的帖子:https://blog.csdn.net/weixin_44049923/article/details/103619882
.vscode下文件:c_cpp_properties.json、CMakeLists.txt、extensions.json、launch.json、settings.json、tasks.json
1、c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/**",
"${workspaceFolder}/C_Cplus/.include**"
],
"browse": {
"path": [
"${workspaceFolder}",
"${workspaceFolder}/**",
"${workspaceFolder}/C_Cplus/.include**"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Users/fb1364/Downloads/x86_64-8.1.0-release-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
2、CMakeLists.txt 略
3.extensions.json
{
"recommendations": [
"mitaki28.vscode-clang"
]
}
4、launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/Users/fb1364/Downloads/x86_64-8.1.0-release-posix-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
5、settings.json
{
"files.associations": {
"vector": "cpp",
"iostream": "cpp",
"cstdio": "cpp",
"new": "cpp",
"queue": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string_view": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"initializer_list": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"ostream": "cpp",
"atomic": "cpp",
"cstdlib": "cpp",
"istream": "cpp",
"ndslib.h": "c",
"inttypes.h": "c",
"platform.h": "c",
"ae350.h": "c",
"atcsmu100.h": "c"
},
"C_Cpp.clang_format_sortIncludes": true, // 格式化时调整include的顺序(按字母排序)
"clang.cflags": [ // 控制c语言静态检测的参数
"--target=x86_64-w64-mingw32",
"-I",
"C_Cplus/.include/**",
"-std=c11",
"-Wall"
],
"clang.cxxflags": [ // 控制c++静态检测时的参数
"--target=x86_64-w64-mingw32", // clang另一个插件无法更改这个,所以头文件找不到报错
"-I",
"C_Cplus/.include/**", // 自己写头文件的时候这里要改,包含进去,不然静态检测会检测不到头文件
"-std=c++17",
"-Wall"
],
"clang.completion.enable": true,
"openhab.useRestApi": false
/// code-runner
/// "code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法输入
/// "code-runner.executorMap": {
/// "c": "cd $dir && clang '$fileName' -o '$fileNameWithoutExt.exe' -I './include/' -Wall -g -O2 -static-libgcc --target=x86_64-w64-mingw -std=c11 && &'$dir$fileNameWithoutExt'",
/// "cpp": "cd $dir && clang++ '$fileName' -o '$fileNameWithoutExt.exe' -I './include/' -Wall -g -O2 -static-libgcc --target=x86_64-w64-mingw -std=c++17 && &'$dir$fileNameWithoutExt'"
/// // "c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -O2 -static-libgcc --target=x86_64-w64-mingw -std=c11 && $dir$fileNameWithoutExt",
/// // "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -O2 -static-libgcc --target=x86_64-w64-mingw -std=c++17 && $dir$fileNameWithoutExt"
/// }, // 控制Code Runner命令;未注释的仅适用于PowerShell(Win10默认),文件名中有空格也可以编译运行;注释掉的适用于cmd(win7默认),也适用于PS,文件名中有空格时无法运行
/// "code-runner.saveFileBeforeRun": true, // run code前保存
/// "code-runner.preserveFocus": true, // 若为false,run code后光标会聚焦到终端上。如果需要频繁输入数据可设为false
/// "code-runner.clearPreviousOutput": false, // 每次run code前清空属于code runner的终端消息,默认false
/// "code-runner.ignoreSelection": true // 默认为false,效果是鼠标选中一块代码后可以单独执行,但C是编译型语言,不适合这样用
}
6、tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "clang++",
// "command": "C:/Users/fb1364/Downloads/x86_64-8.1.0-release-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",
"-I",
"${workspaceFolder}/C_Cplus/.include", // 我有自己编写的头文件在./include文件夹下,所以包含
// "-g", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接libgcc,一般都会加上
"--target=x86_64-w64-mingw32", // clang的默认target为msvc,不加这一条就会找不到头文件;用gcc或者Linux则掉这一条
"-std=c++17", // C++最新标准为c++17,或根据自己的需要进行修改
],
"options": {
"cwd": "${workspaceFolder}"
},
"presentation": {
"echo": true,
"reveal": "always", // 执行任务时是否跳转到终端面板,可以为always,silent,never。具体参见VSC的文档
"focus": true, // 设为true后可以使执行task时焦点聚集在终端,但对编译C/C++来说,设为true没有意义
"panel": "shared", // 不同的文件的编译信息共享一个终端面板
"clear": false
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}