OpenCV application build with static libraries

Hi ,

I am trying to compile one of basic c++ application[get opencv version] using opencv static library.
I have followed below procedure.

  1. Clone the opencv source code.
  2. "cmake -DBUILD_SHARED_LIBS=OFF " to build only static libraries.
  3. Copied the libopencv_core.a to my application folder.
  4. Compiling the application as below.
    command: g++ test.cpp -o test -L. -lopencv_core
    **Output: **
    /tmp/ccmVzIw6.o: In function cv::String::~String()':** **test.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to cv::String::deallocate()'
    /tmp/ccmVzIw6.o: In function cv::String::operator=(cv::String const&)':** **test.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to cv::String::deallocate()'
    collect2: error: ld returned 1 exit status

Any suggestion, how can i compile an application using opencv static library. I dont want to install the opencv to my laptop/board.

Thanks & regards
Surya

Hi @surya_mistral

This kind of error is usually about missing library.
The error tell us it cv::String assign operator and destructor invoke deallocate() but can’t find it in any library from your compiler command line.
cv.String is a typedef of std::string. OpenCV heavily rely on C++ standard libraries like this.
I don’t have much experience with static libraries, may be you need to explicitly tell the compiler to include the standard libraries your static one needs?

Yes, correct. That’s why i am trying to provide my static library location by using “-L.” but not sure why i am still getting the issue.

If i install opencv on my system and try command “g++ test.cpp -o test -lopencv_core” , everything works fine. But for standalone opencv build without installation , my application not able to get compiled.

Any suggestion for this ?

When I compile opencv the library is opencv_core, like opencv_core420