https://blog.csdn.net/qq_37429313/article/details/120588483
https://blog.csdn.net/weixin_45717218/article/details/121720410
1.安装 visual studio 2019, 带 windows Sdk 10。
2.安装扩展 Easy C++ Projects
3.打开命令面板(ctrl+shift+p),输入 >easy, 选择新建C++工程
选择2019 MSVC工具集。
4.Easy自动从国外网站下载配置清单。下载失败,则使用当前目
录下的配置好的json文件。
5.c_cpp_properties.json 配置编译环境(cl.exe),
launch.json 配置运行环境(cppvsdbg),
tasks.json 配置运行步骤,由launch.json调用
6.tasks.json 里VsDevCmd.bat配置程序运行的VS环境,使用
Everything工具搜索位置,把完整路径加入到"args"参数里.
7."cppvsdbg"配置项使用“ms-vscode.cpptools-1.11.5-win32-x6”
扩展里的vsdbg.exe来调试程序。
8.CleanRubbish.bat 清理编译生成的文件
- //c_cpp_properties.json
- {
- "version": 4,
- "configurations": [
- {
- "name": "Windows x64 vs2019",
- "includePath": [
- "${workspaceFolder}/**",
- "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/include/**",
- "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/atlmfc/include/**",
- "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/VS/include/**",
- "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt/**",
- "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um/**",
- "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared/**",
- "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt/**",
- "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/cppwinrt/**",
- "C:/Program Files (x86)/Windows Kits/NETFXSDK/4.8/Include/um/**"
- ],
- "defines": [
- //"WIN32",
- "_DEBUG",
- "UNICODE",
- "_UNICODE"
- ],
- "windowsSdkVersion": "10.0.19041.0",
- "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/bin/HostX64/x64/cl.exe",
- "cStandard": "c17",
- "cppStandard": "c++20",
- "intelliSenseMode": "windows-msvc-x64",
- "compilerArgs": [
- ""
- ]
- }
- ]
- }
- //launch.json
- {
- // 使用 IntelliSense 了解相关属性。
- // 悬停以查看现有属性的描述。
- // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
- "version": "2.0.0",
- "configurations": [
- {
- "name": "cl.exe - 生成和调试活动文件",
- "type": "cppvsdbg",
- "request": "launch",
- "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
- "args": [],
- "stopAtEntry": false,
- "cwd": "${fileDirname}",
- "console": "integratedTerminal", //使用内置终端
- //"console": "externalTerminal",
- "preLaunchTask": "cl.exe build active file",
- "postDebugTask": "delete extra files"
- }
- ]
- }
- //tasks.json
- {
- // See https://go.microsoft.com/fwlink/?LinkId=733558
- // for the documentation about the tasks.json format
- "version": "2.0.0",
- "windows": {
- "options": {
- "shell": {
- "executable": "cmd.exe",
- "args": [
- "/C",
- // The path to VsDevCmd.bat depends on the version of Visual Studio you have installed.
- "\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/Tools/VsDevCmd.bat\"",
- "&&"
- ]
- }
- }
- },
- "tasks": [
- {
- "label": "cl.exe build active file", //要跟lunch中的preLaunchTask一致
- "type": "shell",
- "command": "cl.exe",
- "args": [
- "/GS", //启动安全检查,可检测堆栈缓冲区溢出
- "/Od", //禁用优化
- "/W3", //警告等级3
- //"/MDd", //多线程动态链接Debug版本,调用库(MSVCRT.lib + MSVCR80.DLL),为默认选项
- "/MTd", //多线程静态链接Debug版本,调用库(LIBCMT.lib)
- "/ZI", //用于“编辑并继续”的程序数据库
- "/EHsc", //启用C++异常
- "/Fe:", //指定编译器创建的 .exe或 DLL 的名称和目录。
- //"${fileDirname}/${fileBasenameNoExtension}.exe",
- "${workspaceFolder}/${fileBasenameNoExtension}.exe",
- "${file}"
- // https://docs.microsoft.com/zh-cn/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
- ],
- "problemMatcher": ["$msCompile"],
- "group": {
- "kind": "build",
- "isDefault": true
- }
- },
- {
- "type": "shell",
- "label": "delete extra files",
- "command": "${workspaceFolder}/CleanRubbish.bat"
- }
- ]
- }
- //CleanRubbish.bat
- @echo off
- set path=%fileDirname%
- for /r %path% %%s in (*.exe *.ilK *.obj *.pdb) do (
- del /f /s /q "%%s"
- )
8.未能完美解决的是VS的有些代码格式在编辑阶段会提示错误,但实际编译没错。