[Solved] error: ‘vector’ does not name a type / error: expected ‘,’ or ‘…’ before ‘

I am using Qt Creator on Ubuntu 15.04. I just installed OpenCV 3.0 using the script provided on the documentation website (here: https://help.ubuntu.com/community/OpenCV). When compiling my code i get some errors (not present before running the script):

/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 [..]

All the errors are listed to be in ‘gpu.hpp’ besides the first one which is:

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

referring to the line in which I put the opencv2/gpu/gpu.hpp include.

I searched Stackoverflow a lot and moved ‘using namespace std’ before the includes but this just changes the error type (they all turn to

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

or something similar).

The includes I put at the top of the code are:

  • iostream
  • stdio.h
  • opencv2/opencv.hpp, opencv2/highgui/highgui_c.h, opencv2/imgproc/imgproc_c.h, opencv2/gpu/gpu.hpp, opencv2/core/core.hpp
  • vector
  • math.h
  • cmath
  • list
  • fstream
  • string
  • iomanip


using namespace std;

using namespace cv;

My .pro project file is:

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = FinalMultimedia


LIBS += -lopencv_core

LIBS += -lopencv_imgproc

LIBS += -lopencv_highgui

SOURCES += main.cpp

Running the Makefile (make VERBOSE=1) I get:

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

in which opencv libraries do not appear at all (dunno why). I am using gcc/g++ having just run update/upgrade so I guess it’ll be 5.1.1. I am a complete Linux beginner, so I’m trying to figure it out. Any help? thank you very much.


I tried to create a new Eclipse project with the same code inside. I set the right include / libraries (had been using opencv / c++ in ecplipse a while ago). I get the same error. wtf

Solution #1:

Moving the namespace line did solve the compilation problem. The undefined reference is a linking problem. Congrats! That’s progress.

Now you just have to determine which opencv lib has that symbol and confirm that your search paths are looking there (They probably are not). You can use readelf to see the symbols inside any particular library. Your missing symbol probably supposed to be inside opencv_core, but I don’t know that. You’ll have to confirm. nm might help you, too. Use man to see how they work — both are easy.

You can also track down the make file Qt creates, and use it from the command line. Add VERBOSE=1 to see every library asked for, and every path spelled out for library searches.

Respondent: Paynomindtous

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.