Configure VS Code for Microsoft C++
https://code.visualstudio.com/docs/cpp/config-msvc
参考VSCode 官方问配置
opencv编译好的bin文件下载
https://github.com/opencv/opencv/releases
visual studio 2019 x64 Native Tools Command Prompt for vs 2019
cl for x64 的编译
opencv 解压的文件路径,运行setup_vars_opencv3.cmd,添加opencv 的dll文件路径,环境变量
在代码目录下运行 code . 启动vscode
code .
输出opencv 3.4.10 的版本号
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
int main(int argc , char ** argv)
{
cout << " hello world" << endl;
cout << cv::getVersionString() << endl;
}
c_cpp_properties.json 文件添加 opencv 头文件文件夹路径
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"F:/project_test/opencv/opencv/build/include",
"F:/project_test/opencv/opencv/build/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
task.json 文件配置 添加 opencv 头文件文件夹路径和opencv_world3410.lib 的文件
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"/I\"F:\\project_test\\opencv\\opencv\\build\\include\"",
"F:\\project_test\\opencv\\opencv\\build\\x64\\vc15\\lib\\opencv_world3410.lib"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}