基本环境配置(网上很多教程)
- 安装C++插件
- 启动MSVC环境(2种方法)
- 手动启动VSStudio的X64 Native Tools Command
- 将上面的启动方式写成batch文件,增加在VSCode配置中
** 重点:2种方式最后都是调用[vcvarsall.bat] Environment initialized for: ‘x64’ **
设置c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${OPENCV454}/include", //vscode 引用目录,以便include不出现红色波浪线
"${OPENCV454}/include/opencv2",
"./debug",
"./" //vscode 引用目录,以便include不出现红色波浪线
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\Hostx64\\x64\\cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
- includePath的设置
- compilerPath设置为cl.exe
- cppStandard是c++不是gnu++
设置tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cl.exe",
"args": [
"/EHsc", //指定异常处理模型/EH{s/a}[c][r][-]
"${file}",
"/Zi", //产生完整的调试信息
"/Fe:", //重命名执行文件
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"/Fo:",
"${fileDirname}\\",
"/nologo",
"/I", //指定include文件搜索路径
"./",
"/I",
"${env:OPENCV454}\\include",
"/I",
"${env:OPENCV454}\\include\\opencv2",
"/link",
"${env:OPENCV454}\\x64\\vc15\\lib\\opencv_world454d.lib",
"./debug/zkAlgDll.lib",
// Ask msbuild to generate full paths for file names.
//"/property:GenerateFullPaths=true",
//"/t:build",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
//"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
- “/I” 是大写的i,每个include路径前面都要加 “/I”。类似VS中的包含引用目录
- "/link"是引用lib的,每个文件不需要单独隔开。类似VS中的库目录
- 环境变量路径的引用方式 e n v : P A T H ,比如: {env:PATH},比如: env:PATH,比如:{env:OPENCV454}
设置launch.json
{
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true, //在main入口处停止
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "build"
}
],
"version": "2.0.0"
}
这里比较简单
复制dll后调试
- 需要将链接的dll手动复制到.exe同级文件夹下,否则无法找到符号。
- 还没有找到能自动打包的方法
CMAKE(待补充)
链接多个文件
链接: 多个.cpp文件