I referred to this to install OpenCV on my Raspberry Pi 2 (which is running on the latest Raspbian with kernel release 4.1.7-v7). I was not able to install libgtk2.0-dev due to dependency errors but I was able to install OpenCV without any errors.
I am trying to cross-compile some simple OpenCV code in Qt for my Raspberry Pi 2. But I am getting the following error at linker stage:
/usr/local/lib/libopencv_calib3d.so: undefined reference to
std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20
My code is:
myFunc {
VideoCapture cap(0);
if (!cap.isOpened()) {
qDebug() << "Cannot open the video cam";
return;
}
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
qDebug() << "Frame size : " << dWidth << " x " << dHeight;
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE);
while (1) {
Mat frame;
bool bSuccess = cap.read(frame);
if (!bSuccess) {
qDebug() << "Cannot read a frame from video stream";
break;
}
imshow("MyVideo", frame);
if (/*condition*/) {
break;
}
}
}
I tried changing the order in which the libraries are linked. But the error still remains. My .pro
file looks this:
QT += core gui quick xml widgets
TARGET = myApp
TEMPLATE = app
QMAKE_CXXFLAGS += -I/mnt/rasp-pi-rootfs/usr/include \
-I/mnt/rasp-pi-rootfs/usr/include/libxml2 \
-I/mnt/rasp-pi-rootfs/usr/include/glib-2.0/glib \
-I/mnt/rasp-pi-rootfs/usr/include/glib-2.0 \
-I/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/glib-2.0 \
-I/mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/glib-2.0/include \
-I/mnt/rasp-pi-rootfs/usr/include/gstreamer-1.0 \
-I/mnt/rasp-pi-rootfs/usr/local/include \
QMAKE_CXXFLAGS += -Wno-psabi
QMAKE_LIBDIR_FLAGS += -L/mnt/rasp-pi-rootfs/usr/lib \
-L/mnt/rasp-pi-rootfs/lib \
-L/mnt/rasp-pi-rootfs/usr/local/lib \
QMAKE_LFLAGS += -lgmodule-2.0 \
-lz \
-lxml2 \
-lgthread-2.0 \
-lrt \
-lglib-2.0 \
-lpthread \
-lgstreamer-1.0 \
-lgobject-2.0 \
-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ts -lopencv_video \
SOURCES += /* all .cpp files */
HEADERS += /* all .h files */
How can I resolve this?
UPDATE
I managed to install libgtk2.0-dev and compile OpenCV again. But the error remains.
I've had the same experience. I'm assuming you are using https://github.com/raspberrypi/tools as your toolchain, but even if you are not the problem is that whatever toolchain you are using it probably predates gcc/g++ 4.9.
The problem is that Jessie (i.e. Raspbian 4.1.X) uses gcc/g++ 4.9 as its toolchain and OpenCV is making use of an STL feature that is new to that version of the compiler. Therefore if your application is built with a toolchain that predates gcc/g++ 4.9, it will not link.
The solution is to either get a toolchain that is at least 4.9 or greater, or stick with the Wheezy release of Raspbian, which uses gcc 4.6.
I detailed my experience with cross compiling an OpenCV app in a post here: https://solderspot.wordpress.com/2016/02/04/cross-compiling-for-raspberry-pi-part-ii.
Hope it is of some help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With