VsCode配置C、C++ opencv环境/编写运行C、C++(Windows)
这个方法不用安装MinGW
1.配置基本文件
首先在文件夹下新建.vscode文件,然后往里面放四个文件,具体的代码如下
.vscode\c_cpp_properties.json
第7,8行换成自己的opencv配置环境
第十六行换成自己的visual studio Hostx86/x64/cl.exe 路径
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/Program Files/opencv/build/include",
"D:/Program Files/opencv/build/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "D:/Program Files/visual studio 2019/VC/Tools/MSVC/14.24.28314/bin/Hostx86/x64/cl.exe",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
.vscode\c_cpp_properties.json
这里的"program": "${fileDirname}\\main.exe"
可以自己指定生成的exe的位置和名称
{
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe debug",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
},
{
"name": "cl.exe build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "cl.exe build active file"
}
]
}
.vscode\settings.json
配置一些需要的头文件
{
"files.associations": {
"fstream": "cpp",
"iostream": "cpp",
"vector": "cpp",
"cmath": "cpp",
"xstring": "cpp",
"array": "cpp",
"deque": "cpp",
"initializer_list": "cpp",
"list": "cpp",
"queue": "cpp",
"type_traits": "cpp",
"xhash": "cpp",
"xtree": "cpp"
},
"python.pythonPath": "D:\\Anaconda3\\python.exe"
}
.vscode\tasks.json
同样这里的17-21行要换成自己的opencv地址
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\main.exe",
"twosum.cpp",
"/I",
"D:/Program Files/opencv/build/include",
"/I",
"D:/Program Files/opencv/build/include/opencv2",
"/link",
"D:/Program Files/opencv/build/x64/vc15/lib/opencv_world410.lib"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": [
"$msCompile"
],
"group": "build"
}
]
}
2.编译
注意,在这个地方,首先要通过x86 x64 Cross Tools Command Prompt for VS 2019 这个打开,才能有vs环境,然后输入文件的地址,输入code,就自动打开vscode。
然后在左侧选第三个,run这里选第二个,点击三角形符号,就可以运行成功了。大功告成!
s Command Prompt for VS 2019 这个打开,才能有vs环境,然后输入文件的地址,输入code,就自动打开vscode。
[外链图片转存中…(img-Vp9K4QjR-1586364065086)]
然后在左侧选第三个,run这里选第二个,点击三角形符号,就可以运行成功了。大功告成!