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
}