【C++开发环境配置】

CL环境变量

PATH

# cmake路径
VisualStudio\IDE\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe
# Ninja路径
VisualStudio\IDE\VC\Auxiliary\Build
# MSBuild路径
VisualStudio\IDE\Msbuild\Current\Bin
# rc.exe路径
Windows Kits\10\bin\10.0.19041.0\x64
# cl.exe和link.exe路径
VisualStudio\IDE\VC\Tools\MSVC\14.30.30705\bin\Hostx64\x64\cl.exe

INCLUDEcl.exe的查找路径

# C++标准库头文件路径
VisualStudio\IDE\VC\Tools\MSVC\14.30.30705\include
# C库头文件路径
Windows Kits\10\Include\10.0.19041.0\ucrt

LIBlink.exe的查找链接路径

# 系统相关的一些库
Windows Kits\10\Lib\10.0.19041.0\um\x64
# C库
Windows Kits\10\Lib\10.0.19041.0\ucrt\x64
# C++开发和调试库
VisualStudio\IDE\VC\Tools\MSVC\14.30.30705\lib\x64

mingw环境变量

需要先安装mingw64和cmake,然后设置PATH环境变量

# make、gcc和ld路径路径
mingw64\bin

CPLUS_INCLUDE_PATHC_INCLUDE_PATHgcc的查找路径

mingw64/x86_64-w64-mingw32/include

LIBRARY_PATHld.exe的查找链接路径

mingw64/x86_64-w64-mingw32/lib

配置launch.json

参考 CmakeTools下配置launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(msvc) Launch",
            "type": "cppvsdbg",//调试器类型
            "request": "launch",//launch调试或者attach调试
            "program": "${command:cmake.launchTargetPath}",//当前CMake Tools下的活跃程序
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [
                {
                    "name": "PATH",
                    "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
                }
            ],
            "externalConsole": true
        }
    ]
}

其中type字段指定调试器类型,cppvsdbg表示MSVC调试器;cppdbg表示gdb或者lldb调试器,通过字段"MIMode": "lldb""MIMode": "gdb"区分调试器类型。

配置task.json

参考CMakeTools+CMakePresets下配置task.json
配置生成cmake缓存。

{
    "type": "cmake",
    "label": "CMake: configure",
    "command": "configure",
    "preset": "${command:cmake.activeConfigurePresetName}",
    "detail": "CMake template configure task"
}

构建生成二进制文件。

{
    "type": "cmake",
    "label": "CMake: build",
    "command": "build",
    "preset": "${command:cmake.activeBuildPresetName}",
    "detail": "CMake template build task"
}

清除缓存。

{
    "type": "cmake",
    "label": "CMake: clean",
    "command": "clean",
    "detail": "CMake template clean task"
}

清除并重新构建。

{
    "type": "cmake",
    "label": "CMake: clean rebuild",
    "command": "cleanRebuild",
    "detail": "CMake template clean rebuild task"
}

CMakePresets配置

文件标准结构如下。

{
    "version":3,
    "cmakeMinimumRequired": {
       "major": 3,
       "minor": 21,
       "patch": 0
    },
    "configurePresets":[],
    "buildPresets":[],
    "testPresets":[],
    "workflow":[]
}

configurePresets

用于配置项目,configurePresets标准结构如下,cacheVariables为cmake内的变量赋值,environment指定环境变量。

"configurePresets": [
  {
    "name": "stm32-base",
    "hidden": true,
    "generator": "Unix Makefiles",
    "binaryDir": "${sourceDir}/build/${presetName}",
    "cacheVariables": {},
    "environment":{},
    "warnings": {}
  }
]

cacheVariable为例

"cacheVariables": {
   "CMAKE_BUILD_TYPE": "Debug",
   "CMAKE_C_COMPILER": "cl",
   "CMAKE_CXX_COMPILER": "cl",
   "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
 }

enviroment为例

"environment": {
   "C_INCLUDE_PATH": "mingw64/x86_64-w64-mingw32/include",
   "CPLUS_INCLUDE_PATH": "mingw64/x86_64-w64-mingw32/include"
}

buildPresets

用于构建程序,configurePresets指定一个configurePresets配置。

"buildPresets": [
   {
       "name": "Linux x64-debug",
       "displayName": "MingGW 2022 Release - amd64 - Debug",
       "configurePreset": "Linux x64",
       "jobs": 8
   }
]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值