vscode 配置 cl.exe 编译 vs c/c++工程

vscode 配置 cl.exe 编译 vs c/c++工程

tasks.json 编译任务(命令窗口打开vscode)

1 需要 运行 (Developer Command Prompt for VS 2022)或者 cmd 输入命令 cmd.exe /c “D:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat”
2 然后输入 code 命令 运行vscode

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "cl.exe Task",
            "command": "D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\SDK\\ScopeCppSDK\\vc15\\VC\bin\\cl.exe",
            "args": [
                "/utf-8",
                "/Zi",
                "/EHsc",
                //生成目标
                "/Fe${workspaceFolder}/Debug/Control.exe", 
                //包含目录
                "/I${workspaceFolder}/Utilities/inc/",    
                "/I${workspaceFolder}/RAF_API_Library/inc/", 
                "/I${workspaceFolder}/Common/",
                "/I${workspaceFolder}/Reference_Design_Driver/inc/",
                //源码
                "${workspaceFolder}/**.c",  
                "${workspaceFolder}/Reference_Design_Driver/src/*.c",
                "${workspaceFolder}/RAF_API_Library/src/*.c", 
                "${workspaceFolder}/Utilities/src/*.c",
                 //连接库
                "/link User32.Lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
            ],
            "options": {
                //生成目录
                "cwd": "${workspaceFolder}/Debug" 
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

tasks.json 编译任务(正常打开vscode)

{    "windows": {
        "options": {
            "shell": {
                "executable": "cmd.exe",
                "args": [
                    "/C",
                    // The path to VsDevCmd.bat depends on the version of Visual Studio you have installed.
                    "D:\\Program^ Files\\Microsoft^ Visual^ Studio\\2022\\Community\\Common7\\Tools\\VsDevCmd.bat",
                    "&&"
                ]
            }
        }
    },
    "tasks": [
        {
            // "type": "cppbuild",
            "type": "shell",
            "label": "cl.exe Task",
            // "command": "\"D:/Program Files/Microsoft Visual Studio/2022/Community/SDK/ScopeCppSDK/vc15/VC/bin/cl.exe\"", //x64 版本
            "command":"\"D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\Hostx64\\x86\\cl.exe\"", //x86 版本
            "args": [
                "/utf-8",
                "/Zi",
                "/EHsc",
                //生成目标
                "/Fe${workspaceFolder}/Debug/Control.exe", 
                //包含目录
                "/I${workspaceFolder}/Utilities/inc/",    
                "/I${workspaceFolder}/RAF_API_Library/inc/", 
                "/I${workspaceFolder}/Common/",
                "/I${workspaceFolder}/Reference_Design_Driver/inc/",
                //源码
                "${workspaceFolder}/**.c",  
                "${workspaceFolder}/Reference_Design_Driver/src/*.c",
                "${workspaceFolder}/RAF_API_Library/src/*.c", 
                "${workspaceFolder}/Utilities/src/*.c",
                 //连接库
                "/link User32.Lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
            ],
            "options": {
                //生成目录
                "cwd": "${workspaceFolder}/Debug" 
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

launch.json 调试器



{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C++ Launch (Windows)",//调试器名称
      "type": "cppvsdbg",
      "request": "launch",
      "program": "${workspaceFolder}/Debug/Control.exe",//目标程序
      "symbolSearchPath": "${workspaceFolder}/Debug;C:\\Windows", //符号路径
      "args": [],//参数
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",//工作目录
      "environment": [],
      "externalConsole": false,
      "preLaunchTask": "cl.exe Task"  //task.json 的 label 字段
    }
  ]
}

c_cpp_properties.json 语法高亮文件包含等等

{
    "env": {//自定义环境变量
        "myIncludePath": [
            "${workspaceFolder}/**",
            "Utilities/inc/**",
            "RAF_API_Library/inc/**",
            "Common/**",
            "Reference_Design_Driver/inc/**",
            "D:/Program Files/Microsoft Visual Studio/2022/Community/SDK/ScopeCppSDK/vc15/VC/include/**",
            "D:/Windows Kits/10/Include/10.0.19041.0/ucrt/**"
        ],
        "myCompilerPath": "D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx86/x86/cl.exe"
    },
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${myIncludePath}" //使用自定义变量
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "${myCompilerPath}", //使用自定义变量
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x86",
            "configurationProvider": "ms-vscode.makefile-tools",
            "browse": {
                "path": [
                   "${myIncludePath}" //使用自定义变量
                ]
            }
        }
    ],
    "version": 4
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值