Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4' building OpenCV on Ubuntu

Tags:

c++

c

opencv

I'm on Ubuntu Trusty and I'm building the following code with this command. I'm new to clang and I could use help debugging these errors. The cpp and hpp files these C bindings are from compile fine. I copied the headers from those files into the below file I have listed here, w.cpp

    clang -std=c++11 w.cpp -o w `pkg-config --cflags --libs opencv`

Here are the errors:

        /usr/bin/ld: /tmp/w-2a90f4.o: undefined reference to
        symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'
        //usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding 
         symbols: DSO missing from command line
        clang: error: linker command failed with exit code 1 
          (use -v to see invocation)

Here is the contents of w.cpp. I'm trying to benchmark code using clang.

        #include <opencv2/c/mat.hpp>
        #include <opencv2/c/opencv_generated.hpp>
        using namespace cv;
        using namespace std;
        using namespace flann;
        using namespace cvflann;


        void cv_delete(char* self) {
             delete self;
        }


        Mat* cv_create_Mat() {
            return new Mat();
        }


        BFMatcher* cv_create_BFMatcher(int normType, bool crossCheck) {
            return new BFMatcher(normType, crossCheck);
        }




        int main () {

         for( int a = 1; a < 20; a++)
           {
              Mat a =  &cv_create_Mat(); 

              cv_delete(a);
           }

        }
like image 540
user3517736 Avatar asked Apr 25 '14 06:04

user3517736


1 Answers

I had the same error using gcc instead of g++, I believe you must use clang++

clang++ -std=c++11 w.cpp -o w `pkg-config --cflags --libs opencv`
like image 178
Panoramidal Avatar answered Oct 23 '22 09:10

Panoramidal