简体   繁体   中英

OpenCV "Undefined reference to 'cv::imread' etc C++

So I've written some very basic OpenCV C++ code to test it's functionality. I am using CodeBlocks on Linux Ubuntu 16.04. I have installed OpenCV correctly, I think, Codeblocks offers 'OpenCV Project' as an option when making a project and whenever I start typing in an OpenCV keyword, it'll expand and suggest keywords.

My problem is that when I attempt to build it, I get

undefined reference to `cv::imread(std::__cxxll::basic_string<char, std::char_traits<ch..

And it repeats this for every opencv function.

I read somewhere that this may have something to do with the archive files and so I'll provide the results when I enter:

pkg-config opencv --libs

into the terminal. The output is:

-L/usr/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core 
-lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui 
-lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree 
-lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching 
-lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -latomic 
-ltbb -lGL -lGLU -lrt -lpthread -lm -ldl

So how can I solve this issue? Should I edit my files in some way?

Thanks very much in advance

Your code has been compiled with a standard library using the std::__cxx11 namespace. Ie, you're probably using g++ 5+ which has a different ABI to previous versions. The opencv libraries you've installed are probably an older ABI, and therefore not compatible.

You can either compile the opencv libraries yourself, use an earlier compiler that matches the ABI of the libries you have, or configure your compiler to use the old ABI.

You can use the macro _GLIBCXX_USE_CXX11_ABI if you're using g++ 5. Before you include and std libs:

#define _GLIBCXX_USE_CXX11_ABI 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM