• vscode配置调用visual studio的编译和调试环境


    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 清理编译生成的文件
     

    1. //c_cpp_properties.json
    2. {
    3. "version": 4,
    4. "configurations": [
    5. {
    6. "name": "Windows x64 vs2019",
    7. "includePath": [
    8. "${workspaceFolder}/**",
    9. "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/include/**",
    10. "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/atlmfc/include/**",
    11. "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/VS/include/**",
    12. "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt/**",
    13. "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um/**",
    14. "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared/**",
    15. "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt/**",
    16. "C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/cppwinrt/**",
    17. "C:/Program Files (x86)/Windows Kits/NETFXSDK/4.8/Include/um/**"
    18. ],
    19. "defines": [
    20. //"WIN32",
    21. "_DEBUG",
    22. "UNICODE",
    23. "_UNICODE"
    24. ],
    25. "windowsSdkVersion": "10.0.19041.0",
    26. "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/bin/HostX64/x64/cl.exe",
    27. "cStandard": "c17",
    28. "cppStandard": "c++20",
    29. "intelliSenseMode": "windows-msvc-x64",
    30. "compilerArgs": [
    31. ""
    32. ]
    33. }
    34. ]
    35. }
    1. //launch.json
    2. {
    3. // 使用 IntelliSense 了解相关属性。
    4. // 悬停以查看现有属性的描述。
    5. // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    6. "version": "2.0.0",
    7. "configurations": [
    8. {
    9. "name": "cl.exe - 生成和调试活动文件",
    10. "type": "cppvsdbg",
    11. "request": "launch",
    12. "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
    13. "args": [],
    14. "stopAtEntry": false,
    15. "cwd": "${fileDirname}",
    16. "console": "integratedTerminal", //使用内置终端
    17. //"console": "externalTerminal",
    18. "preLaunchTask": "cl.exe build active file",
    19. "postDebugTask": "delete extra files"
    20. }
    21. ]
    22. }
    1. //tasks.json
    2. {
    3. // See https://go.microsoft.com/fwlink/?LinkId=733558
    4. // for the documentation about the tasks.json format
    5. "version": "2.0.0",
    6. "windows": {
    7. "options": {
    8. "shell": {
    9. "executable": "cmd.exe",
    10. "args": [
    11. "/C",
    12. // The path to VsDevCmd.bat depends on the version of Visual Studio you have installed.
    13. "\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/Tools/VsDevCmd.bat\"",
    14. "&&"
    15. ]
    16. }
    17. }
    18. },
    19. "tasks": [
    20. {
    21. "label": "cl.exe build active file", //要跟lunch中的preLaunchTask一致
    22. "type": "shell",
    23. "command": "cl.exe",
    24. "args": [
    25. "/GS", //启动安全检查,可检测堆栈缓冲区溢出
    26. "/Od", //禁用优化
    27. "/W3", //警告等级3
    28. //"/MDd", //多线程动态链接Debug版本,调用库(MSVCRT.lib + MSVCR80.DLL),为默认选项
    29. "/MTd", //多线程静态链接Debug版本,调用库(LIBCMT.lib)
    30. "/ZI", //用于“编辑并继续”的程序数据库
    31. "/EHsc", //启用C++异常
    32. "/Fe:", //指定编译器创建的 .exe或 DLL 的名称和目录。
    33. //"${fileDirname}/${fileBasenameNoExtension}.exe",
    34. "${workspaceFolder}/${fileBasenameNoExtension}.exe",
    35. "${file}"
    36. // https://docs.microsoft.com/zh-cn/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
    37. ],
    38. "problemMatcher": ["$msCompile"],
    39. "group": {
    40. "kind": "build",
    41. "isDefault": true
    42. }
    43. },
    44. {
    45. "type": "shell",
    46. "label": "delete extra files",
    47. "command": "${workspaceFolder}/CleanRubbish.bat"
    48. }
    49. ]
    50. }
    1. //CleanRubbish.bat
    2. @echo off
    3. set path=%fileDirname%
    4. for /r %path% %%s in (*.exe *.ilK *.obj *.pdb) do (
    5. del /f /s /q "%%s"
    6. )

    8.未能完美解决的是VS的有些代码格式在编辑阶段会提示错误,但实际编译没错。

  • 相关阅读:
    【视频教程】统计方法在变量变化及变量间关系分析中的应用
    使用现代化 C# 语法简化代码
    C++ 入门防爆零教程(上册)
    写一个带参数的宏MIN(x, y),这个宏输入两个 参数并返回较小的一个。
    14、顺时针打印矩阵
    【Axure高保真原型】航空信息可视化原型模板
    React 开发一个移动端项目(1)
    警惕!又2本期刊被“On Hold”!
    2022年Redis最新面试题第6篇 - Redis淘汰策略
    【ubuntu】 Linux(ubuntu)创建python的虚拟环境
  • 原文地址:https://blog.csdn.net/tiandyoin/article/details/126277550