简体   繁体   English

OpenCV“对'cv :: imread'等的未定义引用C ++

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

So I've written some very basic OpenCV C++ code to test it's functionality. 因此,我编写了一些非常基本的OpenCV C ++代码来测试其功能。 I am using CodeBlocks on Linux Ubuntu 16.04. 我在Linux Ubuntu 16.04上使用CodeBlocks。 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. 我认为我已经正确安装了OpenCV,Codeblocks在创建项目时会提供“ OpenCV项目”作为选项,每当我开始输入OpenCV关键字时,它都会扩展并建议关键字。

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. 并对每个opencv函数重复此操作。

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. 您的代码已使用std :: __ cxx11命名空间通过标准库进行编译。 Ie, you're probably using g++ 5+ which has a different ABI to previous versions. 即,您可能正在使用g ++ 5+,它的ABI与以前的版本不同。 The opencv libraries you've installed are probably an older ABI, and therefore not compatible. 您安装的opencv库可能是较旧的ABI,因此不兼容。

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. 您可以自己编译opencv库,使用与您所拥有的库的ABI相匹配的早期编译器,或将编译器配置为使用旧的ABI。

You can use the macro _GLIBCXX_USE_CXX11_ABI if you're using g++ 5. Before you include and std libs: 如果使用的是g ++ 5,则可以使用宏_GLIBCXX_USE_CXX11_ABI。在包含和std库之前:

#define _GLIBCXX_USE_CXX11_ABI 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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