VSCode MSVC Opencv环境配置

基本环境配置(网上很多教程)

  1. 安装C++插件
  2. 启动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文件

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值