c++ - 错误 : 'vector' does not name a type/error: expected ',' or '...' before '<' token/error: 'vector' has not been declared

标签 c++ qt opencv ubuntu vector

我在 Ubuntu 15.04 上使用 Qt Creator。我刚刚使用文档网站上提供的脚本安装了 OpenCV 3.0(此处:https://help.ubuntu.com/community/OpenCV)。编译我的代码时出现一些错误(在运行脚本之前不存在):

/usr/include/opencv2/gpu/gpu.hpp:432: error: 'vector' does not name a type CV_EXPORTS void merge(const vector& src, GpuMat& dst, Stream& stream = Stream::Null());

/usr/include/opencv2/gpu/gpu.hpp:432: error: expected ',' or '...' before '<' token [..]

/usr/include/opencv2/gpu/gpu.hpp:438: error: 'vector' has not been declared [..]

除第一个错误外,所有错误都列在“gpu.hpp”中:

/[..]/main.cpp:6: In file included from ../[..]/main.cpp:6:0:

引用我放置 opencv2/gpu/gpu.hpp include 的行。

我搜索了很多 Stackoverflow 并在包含之前移动了“using namespace std”,但这只是改变了错误类型(它们都转向了

error: undefined reference to `cv::Mat::zeros(int, int, int)'

或类似的东西)。

我放在代码顶部的包含是:

  • iostream
  • 标准输入输出
  • opencv2/opencv.hpp, opencv2/highgui/highgui_c.h, opencv2/imgproc/imgproc_c.h, opencv2/gpu/gpu.hpp, opencv2/core/core.hpp
  • 载体
  • 数学.h
  • 数学
  • 列出
  • 流媒体
  • 字符串
  • 马尼普

+

using namespace std;

using namespace cv;

我的 .pro 项目文件是:

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = FinalMultimedia

TEMPLATE = app

LIBS += -lopencv_core

LIBS += -lopencv_imgproc

LIBS += -lopencv_highgui

SOURCES += main.cpp\

运行 Makefile (make VERBOSE=1) 我得到:

g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../try -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o main.o ../try/main.cpp

其中根本没有出现 opencv 库(不知道为什么)。我正在使用刚刚运行更新/升级的 gcc/g++,所以我猜它会是 5.1.1。我是一个完整的 Linux 初学者,所以我想弄明白。有什么帮助吗?非常感谢。

更新:

我试图用相同的代码创建一个新的 Eclipse 项目。我设置了正确的包含/库(前一段时间一直在 ecplipse 中使用 opencv/c++)。我犯了同样的错误。卧槽

最佳答案

移动命名空间行确实解决了编译问题。 undefined reference 是一个链接问题。恭喜!这就是进步。

现在您只需确定哪个 opencv 库具有该符号并确认您的搜索路径正在寻找那里(它们可能不是)。您可以使用 readelf 查看任何特定库中的符号。您丢失的符号可能应该在 opencv_core 中,但我不知道。你必须确认。 nm 也可能对您有所帮助。使用 man 查看它们是如何工作的——两者都很简单。

您还可以找到 Qt 创建的 make 文件,并从命令行使用它。添加 VERBOSE=1 以查看请求的每个库,以及为库搜索拼写的每个路径。

关于c++ - 错误 : 'vector' does not name a type/error: expected ',' or '...' before '<' token/error: 'vector' has not been declared,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30918837/

相关文章:

c++ - 按照符号链接(symbolic link)并使用 QFileInfo 获取绝对路径

c++ - 为什么我的类(class)没有通过Qt QUDPSocket接收UDP数据报?

c++ - 无法理解如何使用 drawText for qpainter 旋转文本

c++ - 使用 MFC 在 opencv 中的函数 cvInitImageHeader 中输入 roi 错误

python - 使用 OpenCV VideoWriter 将 RTSP 流存储为视频文件

c++ - 对`cv::VideoCapture::VideoCapture(int) 的 undefined reference

c# - 相当于C#中的sscanf_s?

c++ - 我用STL写了一个bin_search,不过这是个小BUG

c++ - 未在范围内声明的对象

c++ - 如何匹配轮廓以检测图像上字母的 ASCII?