【发布时间】:2021-01-25 12:18:18
【问题描述】:
我知道这个问题已经多次提出,但即使尝试了我在 Internet 上找到的所有可能的建议,我也找不到让我的简单程序工作的方法。
故事如下:我正在使用 Visual Studio Code 启动一个 C++ 程序,并且我想使用 openCV 库。由于我是这些东西的初学者,所以我首先从 opencv 教程中剪切和粘贴一些简单的程序。当我尝试构建时,VSC 找不到 openCV 文件并抛出错误。
C:\Users\Roberto\Documents\Program Data Files\C++\SVM\Test1.cpp:5:10: 致命错误:opencv2/core.hpp:没有这样的文件或目录#include
程序以这些#include 开始(没有找到任何opencv2 文件):
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
这是我的 launch.json:
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"MIMode": "gdb",
"miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
}
]
这是 c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/Users/Roberto/Documents/Program Data Files/C++/opencv/build/include/*",
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x86"
}
],
"version": 4
}
这个想法是openCV文件在includePath的目录中。 我在几个地方读过我不应该使用 includePath 而只使用 compilePath。现在,不知道是什么意思,但我也尝试将openCV包含文件的整个文件夹复制到coplier目录中,但没有成功。
一些笔记。 Intellisense“找到”文件,因为如果我开始输入“#include 我也尝试通过在task.json中添加-I指令来绕过这个问题: } 在这种情况下,我得到一个不同的错误,即所有 openCV 函数调用都被标记为“未定义对 cv::... 的引用” 关于如何使这件事发挥作用的任何建议?{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-IC:/Users/Roberto/Documents/Program Data Files/C++/opencv/build/include"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
【问题讨论】:
标签: c++ opencv visual-studio-code include