OPENCV compilation link error due to different version of C + + class Library

Source: Internet
Author: User

Too long to read: GCC4 and GCC5 Use the C + + standard library, string names are not the same, resulting in link errors.

Before using OpenCV under Ubuntu, everything worked. Later when compiling again, the connector hints that some library functions could not be found:

main.o:在函数‘main’中:main.cpp:15constint)’未定义的引用main.cpp:22constint)’未定义的引用main.cpp:23constconst1 exit status

The source file also uses other library functions, why only these functions can not be found? Later ruled out a large number of errors, determined not because the library file can not be found, the bug of the pit dad ...

Analyze the output's target file, list its symbol table: nm -c main.cpp.o , and discover that it references external symbols:

...                 constint)                 constint)                 constconst&)...

Find the data and learn that these functions come from the Opencv_highgui library file ( /usr/lib/x86_64-linux-gnu/libopencv_highgui.so ) and can also list its symbol table nm -C opencv_highgui.a (the corresponding static library):

 ... 0000000000000000  T cv::imread (std::__cxx11::basic_string<char  , Std::char_traits<char , Std::allocator<char  > > span class= "DT" >const  &, int ) 0000000000000000  T CV:: Namedwindow (Std::__cxx11::basic_string<char , Std::char_traits< Char , Std::allocator<char  > > const  &, int ) 0000000000000000  T cv::imshow (std::__cxx11::basic_string<char , Std::char_traits<char ;, std::allocator< char  > > const  &, Cv::_inputarray const  &) ...  

Being able to see the prototype of the library function is inconsistent with the prototype in my own program. In contrast, the name of the standard library string is different. My own program is in the std::string library std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > .

It was later recalled that the GCC4.9 version (and C + + standard library) was installed in the previous period in order to be compatible with MATLAB. Restore the gcc5.x version compile, link, no problem occurs again.

To summarize, it is because my OpenCV library was compiled by Ubuntu official using C++5 's standard library, and the program I wrote was c++4.9 library. Two libraries standard library string names are not the same in the target code, resulting in the inability to link.

OPENCV compilation link error due to different version of C + + class Library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.