# OpenCV application build with static libraries

**URL:** <https://forum.opencv.org/t/opencv-application-build-with-static-libraries/1949>\
**Category:** C++\
**Tags:** build\
**Created:** [March 4, 2021, 10:55am UTC](https://forum.opencv.org/t/opencv-application-build-with-static-libraries/1949 "2021-03-04T10:55:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![surya\_mistral](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@surya\_mistral](https://forum.opencv.org/u/surya_mistral)\
**Post date:** [March 4, 2021, 10:55am UTC](https://forum.opencv.org/t/opencv-application-build-with-static-libraries/1949/1 "2021-03-04T10:55:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alejandro\_Silvestri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alejandro_silvestri/32/357_2.png) [@Alejandro\_Silvestri](https://forum.opencv.org/u/Alejandro_Silvestri)\
**Post date:** [March 4, 2021, 12:14pm UTC](https://forum.opencv.org/t/opencv-application-build-with-static-libraries/1949/2 "2021-03-04T12:14:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![surya\_mistral](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@surya\_mistral](https://forum.opencv.org/u/surya_mistral)\
**Post date:** [March 4, 2021, 12:57pm UTC](https://forum.opencv.org/t/opencv-application-build-with-static-libraries/1949/3 "2021-03-04T12:57:25Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![visualbill](https://avatars.discourse-cdn.com/v4/letter/v/b38774/32.png) [@visualbill](https://forum.opencv.org/u/visualbill)\
**Post date:** [March 4, 2021, 10:49pm UTC](https://forum.opencv.org/t/opencv-application-build-with-static-libraries/1949/4 "2021-03-04T22:49:31Z")

</div>

When I compile opencv the library is opencv\_core, like opencv\_core420
