You are not logged in.

#1 2016-12-26 14:23:27

greati
Member
Registered: 2016-12-26
Posts: 2

[Solved] Can't compile C++ code when using OpenCV's objdetect library

Hello,

I have the following code, in a file named haar_tests.cpp:

#include <opencv2/core/core.hpp>                // opencv basics
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>      // imread
#include <opencv2/highgui/highgui.hpp>          // namedWindow
#include <opencv2/objdetect/objdetect.hpp>     // Cascade Classifier
#include <iostream>
#include <vector>                          

cv::String cascade_filter_plates = "filter_br_plates_openalpr.xml";
cv::CascadeClassifier plates_cascade;

int main() {
        // Loading the image
        cv::Mat image = cv::imread("../../images/20161223_111802.jpg");
        // Loading the cascade
        if (!plates_cascade.load(cascade_filter_plates)) {
                printf("Error on loading the XML filter!");
                return -1; 
        }
        return 0;
}

When I try to compile it using the line

g++ haar_tests.cpp -o haar_tests -std=c++11 `pkg-config opencv --libs --cflags`

I get the following error:

/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib/libopencv_objdetect.so: undefined reference to `std::thread::_State::~_State()@GLIBCXX_3.4.22'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib/libopencv_objdetect.so: undefined reference to `std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())@GLIBCXX_3.4.22'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib/libopencv_objdetect.so: undefined reference to `typeinfo for std::thread::_State@GLIBCXX_3.4.22'
collect2: error: ld returned 1 exit status

Does anybody know how do I solve it?

Thank you in advance.

Last edited by greati (2016-12-26 15:03:01)

Offline

#2 2016-12-26 14:32:39

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [Solved] Can't compile C++ code when using OpenCV's objdetect library

Works fine here.  But what is `/usr/lib/gcc/x86_64-unknown-linux-gnu/`?

I take it you aren't running archlinux?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2016-12-26 14:34:44

jaergenoth
Member
Registered: 2015-01-16
Posts: 85

Re: [Solved] Can't compile C++ code when using OpenCV's objdetect library

I get the same error when trying to compile with older gcc (5.4.0). Newest version of gcc (6.2.1) seems to work.
When was the last time you updated your system? Your gcc seems to be version 5.3.0, which came out in 2015.

Offline

#4 2016-12-26 15:02:00

greati
Member
Registered: 2016-12-26
Posts: 2

Re: [Solved] Can't compile C++ code when using OpenCV's objdetect library

Yes, I'm using archlinux.

I actually have just solved the problem by updating my gcc as suggested. The "x86_64-unknown-linux-gnu" now is "x86_64-pc-linux-gnu".

Now, the question is: why it wasn't updated when I executed

sudo pacman -Syu

?

I did it two days ago and did it now, and my gcc remained at version 5.4.0.

Well, I think that question is out of this topic and I'll search about this new problem later.

Thank you very much!

Offline

#5 2016-12-26 17:56:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [Solved] Can't compile C++ code when using OpenCV's objdetect library

6.2.1 was built at the end of August and was in the main repos in September.  It sounds like you did a partial upgrade.  Perhaps you attempted to run pacman -Syu, but it may have failed, or given a prompt that you didn't respond to so it never completed the update.  Then you installed opencv which resulted in the partial upgrade situation.

If you want to know why/how you got into that situation we'd need to see your pacman log (at least).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB