本文介绍了对cv :: imread的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问过几次了,但是我仍然为简单的opencv代码的链接器错误未定义参考而苦苦挣扎.这是我的代码:

I know this has been asked several times but still I am struggling with linker error undefined reference for simple opencv code. This is my code:

#include <opencv2/highgui.hpp>
using namespace cv;

int main(int argc, char** argv) {
    Mat inputImage = imread(argv[1]);
    imshow("Input Image", inputImage);

    waitKey(0);
}

我正在使用Eclipse IDE,cygwin g ++编译器和opencv 3.0.我已正确地将包含路径,库搜索路径指定为"C:\ opencv \ build \ x64 \ vc11 \ lib"& "C:\ opencv \ build \ x64 \ vc11 \ staticlib"和库:opencv_highgui300,opencv_highgui300d,opencv_core300,opencv_core300d,opencv_imgcodecs300,opencv_imgcodecs300d而且我认为这些对于这个简单的代码已经足够,如opencv文档中所述.但是仍然由于提到的imread,imshow,waitkey而出现链接器错误.我尝试使用pkg-config,但pkg-config在我的64位计算机上出现问题:加载共享库时出错,也无法解决.

I am using eclipse IDE, cygwin g++ compiler and opencv 3.0.I have correctly given include path, library search path as "C:\opencv\build\x64\vc11\lib" & "C:\opencv\build\x64\vc11\staticlib" and libraries: opencv_highgui300,opencv_highgui300d,opencv_core300,opencv_core300d,opencv_imgcodecs300,opencv_imgcodecs300dand I think these are quite sufficient for this simple code as clear from opencv documentation. But still getting linker error for imread, imshow, waitkey as mentioned.I tried with pkg-config but pkg-config is giving problem on my 64 bit machine: error while loading shared libraries and couldn't solve that either.

下面是构建输出:
全部制作
生成文件:../ShowImage.cpp
调用:Cygwin C ++编译器
g ++ -I"C:\ opencv \ build \ include \ opencv" -I"C:\ opencv \ build \ include" -O0 -g3 -Wall -c -fmessage-length = 0 -MMD -MP -MF"ShowImage. d"-MT" ShowImage.d"-o" ShowImage.o" ../ShowImage.cpp完成的建筑物:../ShowImage.cpp

Below is build output:
make all
Building file: ../ShowImage.cpp
Invoking: Cygwin C++ Compiler
g++ -I"C:\opencv\build\include\opencv" -I"C:\opencv\build\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"ShowImage.d" -MT"ShowImage.d" -o "ShowImage.o" "../ShowImage.cpp"Finished building: ../ShowImage.cpp

构建目标:Test.exe
调用:Cygwin C ++链接器
g ++ -L"C:\ opencv \ build \ x64 \ vc11 \ lib" -L"C:\ opencv \ build \ x64 \ vc11 \ staticlib" -o"Test.exe" ./ShowImage.o -lopencv_highgui300 -lopencv_highgui300d- lopencv_core300 -lopencv_core300d -lopencv_imgcodecs300 -lopencv_imgcodecs300d

./ShowImage.o:在函数main':**/cygdrive/d/Gateway_Firmware/ImProcessing_WS/Test/Debug/../ShowImage.cpp:12: undefined reference to cv :: imread(cv :: String const& ;, int)'中/cygdrive/d/Gateway_Firmware/ImProcessing_WS/Test/Debug/../ShowImage.cpp:12:(.text+0x44):针对未定义符号`cv :: imread(cv :: String const& amp; ,int)'

Building target: Test.exe
Invoking: Cygwin C++ Linker
g++ -L"C:\opencv\build\x64\vc11\lib" -L"C:\opencv\build\x64\vc11\staticlib" -o "Test.exe" ./ShowImage.o -lopencv_highgui300 -lopencv_highgui300d -lopencv_core300 -lopencv_core300d -lopencv_imgcodecs300 -lopencv_imgcodecs300d

./ShowImage.o: In function main':**/cygdrive/d/Gateway_Firmware/ImProcessing_WS/Test/Debug/../ShowImage.cpp:12: undefined reference tocv::imread(cv::String const&, int)'/cygdrive/d/Gateway_Firmware/ImProcessing_WS/Test/Debug/../ShowImage.cpp:12:(.text+0x44): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cv::imread(cv::String const&, int)'

我错过了什么吗?任何帮助将不胜感激.

Am I missing anything? Any help will be greatly appreciated.

推荐答案

万一有人因其他原因而迷失了方向,我会遇到一个问题,即x86 Ubuntu 18.04 docker容器上的OpenCV链接选项与Ubuntu 16.04上的不同Raspberry Pi,我通过将链接器标志-lopencv_imgcodecs替换为链接器标志-lopencv_highgui.

In case anyone stumbles upon this for other reasons, I have had the problem where OpenCV link options on an x86 Ubuntu 18.04 docker container differ from those on an Ubuntu 16.04 Raspberry Pi, and I solved the problem by replacing the linker flag -lopencv_imgcodecs with the linker flag -lopencv_highgui.

这篇关于对cv :: imread的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-31 22:50