c++ - 在 Ubuntu 18.04 的 VIsual Studio 代码中为 C++ 设置 OpenCV
问题描述
可能有几个类似的问题,我读了大部分,但它并没有解决我的问题。这是我第一次设置这个。我会总结一下我所做的。
首先,我按照此链接从源代码(opencv 和 opencv_contrib)(版本 4.5.2)安装了 OpenCV 。之后我发现我需要 CMakeLists.txt 并将此内容放入其中:
cmake_minimum_required(VERSION 3.0.0)
project(opeet)
find_package( OpenCV 4 REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(opeet moje.cpp)
target_link_libraries( opeet ${OpenCV_LIBS} )
这个 CMake 文件是这样说的:
Found OpenCV: /usr/local (found suitable version "4.5.2", minimum required is "4")
所以我想它正确地找到了 OpenCV。
当我运行这个程序时:
#include<iostream>
#include<opencv2/opencv.hpp>
int main() {
std::cout<<"hahahahha"<<std::endl;
return 0;
}
我得到错误:opencv2/opencv_modules.hpp not found
。
然后我对我的目录组织做了一点改变。当我安装 OpenCV 时,它安装在目录中:
/usr/local/include/opencv4/opencv2
我将目录移动 opencv2
到include
(因此opencv4
被删除)。
所以现在 OpenCV 的目录是:
/usr/local/include/opencv2
现在上面的程序编译得很好。
但是现在如果我添加这一行(只是声明变量)cv::Mat q;
,当我编译它会给我错误:
/home/faris/Desktop/Opeet/moje.cpp:5: undefined reference to `cv::Mat::Mat()'
/home/faris/Desktop/Opeet/moje.cpp:5: undefined reference to `cv::Mat::~Mat()'
现在我的痛苦开始了。我无法解决这个问题。我尝试了很多东西。我尝试添加路径,c_cpp_properties.json
但没有帮助。我将发布文件,.vscode
所以也许有一些错误。
c_cpp_properties.json
:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
如果有人可以帮助我,我将不胜感激,我不知道该怎么办了。
解决方案
推荐阅读
- python - 修复 422 响应 python 请求获取
- r - R函数用任何整数替换字符
- android-studio - 使用 DragLinearLayout 时如何获取子位置
- python - 使用多边形坐标将带注释的图像转换为二进制蒙版图像
- gitlab - 尝试从 GitLab 将自定义 Helm 存储库添加到本地时出错
- python - 如何从 Python 中的字符串数组中删除正斜杠?
- python - 是否可以相对于屏幕尺寸设置海龟的位置
- flutter - NoSuchMethodError 被抛出构建选项卡(脏,状态:_TabsState#fefcf):方法 '[]' 在 null 上被调用
- sql - 我们可以更新定义为在不同表中定义的唯一记录的外键的记录吗?
- excel - 仅将 VBA 代码应用于主题中包含“字符串”的电子邮件