OpenCV 2.4.1未定义的参考 [英] OpenCV 2.4.1 undefined references

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

问题描述

我最近在运行Ubuntu 12.04(64位)的桌面上安装了OpenCV 2.4.1,其中本教程,但每次尝试编译代码时,即使是使用预构建编译脚本的包含示例,从 cv 命名空间获取未定义的引用。



我目前正在编译的代码是本例来自OpenCV文档。我已经尝试了3种不同的编译方法这段代码:

I-按照文档站点的指示使用CMake;
$ b II-使用gcc和使用以下命令执行pkg-config:

  gcc`pkg-config --cflags opencv` display_image.cpp`pkg-config  - -libs opencv` -o DisplayImage 

III-我们直接添加库和头文件路径:

  CC = g ++ 
INCLUDE = -I / usr / local / include -I / usr / local / include / opencv

LIBS = -L / usr / local / lib -lopencv_core -lopencv_highgui

:%.cpp
$(CC)-o $ @ $< $(INCLUDE)$(LIBS)

所有这些产生相同的输出:


$ b $ pre $ /tmp/ccufJQVm.o:函数`main':
display_image.cpp :(。text + 0x9b):undefined reference到`cv :: imread(std :: basic_string< char,std :: char_traits< char> ;, std :: allocator< char>> const&,int)'
display_image.cpp :( .text + 0x13f ):未定义对`cv :: namedWindow(std :: basic_string< char,std :: char_traits< char> ;, std :: allocator< char>> const&,int)'的引用'
display_image.cpp :( .text + 0x1a1):对cv :: imshow(std :: basic_string< char,std :: char_traits< char> ;, std :: allocator< char>> const&; cv :: _ InputArray const&)的未定义引用'
collect2:ld返回1退出状态$ b $ make:*** [display_image]错误1

我发现了一些与我的相关的其他问题,但他们的解决方案都不适合我。我真的很想了解什么是导致这些未定义的引用,因为所有的库和头文件正是它们应该在的地方。



任何类型的帮助都会以我永恒的爱和感激之心得到回报。
H546163809H



添加一些命令的回显以澄清问题:

  $ pkg-config --cflags opencv 
-I / usr / local / include / opencv -I / usr / local / include
$ pkg-config --libs opencv
/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so / usr / local / lib / libopencv_flann。所以/usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so / usr / local / lib / libopencv_ml。所以/usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so / usr / local / lib / libopencv_ts。所以/usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so

现在添加一个更详细的编译输出(使用-Wall和-v)

  g ++ -v -Wall -o display_image display_ image.cpp -I / usr / local / include -I / usr / local / include / opencv -L / usr / local / lib -lopencv_core -lopencv_highgui 
使用内置规格。
COLLECT_GCC = g ++
COLLECT_LTO_WRAPPER = / usr / lib / gcc / x86_64-linux-gnu / 4.6 / lto-wrapper
目标:x86_64-linux-gnu
配置为:。 ./src/configure -v --with-pkgversion ='Ubuntu / Linaro 4.6.3-1ubuntu5'--with-bugurl = file:///usr/share/doc/gcc-4.6/README.Bugs --enable -languages = c,c ++,fortran,objc,obj-c ++ --prefix = / usr --program-suffix = -4.6 --enable-shared --enable-linker-build-id --with-system-zlib - -libexecdir = / usr / lib --without-included-gettext --enable-threads = posix --with-gxx-include-dir = / usr / include / c ++ / 4.6 --libdir = / usr / lib --enable -nls --with-sysroot = / --enable-clocale = gnu --enable-libstdcxx-debug --enable-libstdcxx -time = yes --enable-gnu-unique-object --enable-plugin --enable- objc-gc --disable-werror --with-arch-32 = i686 --with-tune = generic --enable-checking = release --build = x86_64-linux-gnu --host = x86_64-linux-gnu - -target = x86_64-linux-gnu
线程模型:posix
gcc版本4.6.3(Ubuntu / Linaro 4.6.3-1ubuntu5)
COLLECT_GCC_OPTIONS =' - v''-Wall'' -o''display_image''-I'/ usr / local / include''-I''/ usr / local / include / opencv''-L / usr / local / lib''-shared-libgcc'' - mtune = generic''-march = x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/cc1plus -quiet -v -I / usr / local / include -I / usr / local / include / opencv -imultilib。 -multiarch x86_64-linux-gnu -D_GNU_SOURCE display_image.cpp -quiet -dumpbase display_image.cpp -mtune = generic -march = x86-64 -auxbase display_image -Wall -version -fstack-protector -o /tmp/ccDB7q8G.s
GNU C ++(Ubuntu / Linaro 4.6.3-1ubuntu5)版本4.6.3(x86_64-linux-gnu)$ GNU C版本4.6.3编译的
,GMP版本5.0.2,MPFR版本3.1.0- p3,MPC版本0.9
GGC启发式:--param ggc-min-expand = 100 --param ggc-min-heapsize = 131072
忽略不存在的目录/ usr / local / include / x86_64-linux -gnu
忽略不存在的目录/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include
忽略重复的目录/ usr / local / include
,因为它是复制系统目录的非系统目录
#include...搜索从这里开始:
#include< ; ...>搜索从这里开始:
/ usr / local / include / opencv
/usr/include/c++/4.6
/usr/include/c++/4.6/x86_64-linux-gnu/。
/usr/include/c++/4.6/backward
/usr/lib/gcc/x86_64-linux-gnu/4.6/include
/ usr / local / include
/ usr /lib/gcc/x86_64-linux-gnu/4.6/include-fixed
/ usr / include / x86_64-linux-gnu
/ usr / include
搜索列表结束。
GNU C ++(Ubuntu / Linaro 4.6.3-1ubuntu5)版本4.6.3(x86_64-linux-gnu)
由GNU C版本4.6.3编译,GMP版本5.0.2,MPFR版本3.1。 0-p3,MPC版本0.9
GGC启发式:--param ggc -min-expand = 100 --param ggc-min-heapsize = 131072
编译器可执行校验码:65b5171ac1bd7b3f07dbea6bdb24be3d
COLLECT_GCC_OPTIONS =' -v''-Wall''-o''display_image''-I'/ usr / local / include''-I''/ usr / local / include / opencv'-L / usr / local / lib' '-shared-libgcc''-mtune = generic''-march = x86-64'
as --64 -o /tmp/cchdK0Uq.o /tmp/ccDB7q8G.s
COMPILER_PATH = / usr /lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc /x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH = / usr / lib / gcc / x86_64-linux-gnu / 4.6 /:/ usr / lib / GCC / x86_64的-Linux的GNU / 4.6 /../../../ x86_64的-Linux的GNU /:/ usr / lib中/ GCC / x86_64的-Linux的GNU / 4.6 /../../../ ../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib /x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr / lib /
COLLECT_GCC_OPTIONS =' - v''-Wall''-o''display_image''-I''/ usr / local / include''-I''/ usr / local / include / opencv' '-L / usr / local / lib''-shared-libgcc''-mtune = generic''-march = x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/collect2 --sysroot = / --build-id --no-add-needed --as-needed --eh-frame-hdr -m elf_x86_64 --hash-style = gnu -dynamic-linker / lib64 / ld-linux- x86-64.so.2 -z relro -o display_image /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o / usr / lib /gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L / usr / local / lib -L ​​/ usr / lib / gcc / x86_64-linux-gnu / 4.6 -L / usr / lib / gcc / x86_64-linux-gnu / 4.6 /../../../ x86_64-linux -gnu -L / usr / lib / gcc / x86_64-linux-gnu / 4.6 /../../../../ lib -L ​​/ lib / x86_64-linux-gnu -L / lib /../ lib -L ​​/ usr / lib / x86_64-linux-gnu -L / usr / lib /../ lib -L ​​/ usr / lib / gcc / x86_64-l inux-gnu / 4.6 /../../ .. /tmp/cchdK0Uq.o -lopencv_core -lopencv_highgui -lstdc ++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc / usr / lib / gcc / x86_64-linux-gnu /4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
/tmp/cchdK0Uq.o:在main函数中:
display_image.cpp :(。text + 0x9b):对cv :: imread(std :: basic_string< char,std :: char_traits< char> ;, std :: allocator<炭> > const&; int)'
display_image.cpp :(。text + 0x13f):未定义对`cv :: namedWindow(std :: basic_string< char,std :: char_traits< char> ;, std :: allocator& (std :: basic_string< char,std :: char_traits< char>,std :: const&,int)'
display_image.cpp :(。text + 0x1a1) :: allocator< char>> const&;,cv :: _ InputArray const&)'
collect2:ld返回1退出状态$ b $ make:*** [display_image]错误1


解决方案

我的猜测是你缺少一些* -dev 包。本教程在开始时列出了一大堆,并且根据我的经验,这些通常是导致编译失败的直接原因。
不幸的是,你可以从编译器获得一个间接消息。我猜你所提到的错误信息只是构建输出的尾部,这可能是真正的原因。你必须做的是重定向构建输出(使用 tee 你可以拆分它并在控制台上看到它并获取构建日志),或者你已经有一个构建登录。研究构建日志并查看编译期间出现的第一个第二个错误消息。这可以更好地指示丢失的库或开发包。
这只是一个猜测,准则。为我们提供整个构建日志。如果输出结果很短,请尝试增加输出冗长度。 我比较了由@Gaurav Raj链接的Ubuntu 11.04教程和您的Ubuntu 12.04教程。
我尝试安装这些软件包:


  • libpng12-dev
  • libpng ++ -dev

  • libpng3

  • libpnglite-dev

  • libpngwriter0-dev
  • zlib1g-dbg

  • zlib1g-dev

  • pngtools

  • libjpeg8-dev

  • libjpeg8-dbg

  • libjpeg-progs
  • ffmpeg

  • libgstreamer0.xy -0-dbg(xy应该是Ubuntu 12.04的一个版本,对于Ubuntu 11.04,这个版本可能比0.10更新)

  • libgstreamer0.xy-dev
  • libxine-dev

  • libunicap2-dev

  • swig

  • libdc1394-utils



  • 在安装之前,您可以通过说明 dpkg -l | grep $ {pkg_name_to_check}


    I have recently installed OpenCV 2.4.1 on a desktop running Ubuntu 12.04(64-bits) following this tutorial,but every time I try to compile a code,even the included samples that use a pre-built compiling script,I get undefined references regarding every function from the cv namespace.

    The code I am currently trying to compile is this example from the OpenCV documentation.I have tried 3 different approaches to compile this code:

    I- Using CMake,as instructed by the documentation site;

    II- Using gcc and pkg-config with the following command:

    gcc `pkg-config --cflags opencv` display_image.cpp `pkg-config --libs opencv` -o DisplayImage
    

    III- Using my own makefile and adding the library and header paths directly:

    CC = g++
    INCLUDE = -I/usr/local/include -I/usr/local/include/opencv
    
    LIBS = -L/usr/local/lib -lopencv_core -lopencv_highgui 
    
    %: %.cpp 
        $(CC) -o $@ $< $(INCLUDE) $(LIBS) 
    

    And all of them produce the same output:

    /tmp/ccufJQVm.o: In function `main':
    display_image.cpp:(.text+0x9b): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    display_image.cpp:(.text+0x13f): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    display_image.cpp:(.text+0x1a1): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
    collect2: ld returned 1 exit status
    make: *** [display_image] Error 1
    

    I have found some other questions that where related to mine,but none of their solutions worked out for me.And I would really like to understand what is causing these undefined references,since all the libraries and headers are exactly where they are supposed to be.

    Any kind of help would be repaid with my eternal love and gratitude. H546163809H

    Adding the echo of some commands to clarify the question:

    $pkg-config --cflags opencv
    -I/usr/local/include/opencv -I/usr/local/include 
    $pkg-config --libs opencv
    /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
    

    Adding now a more verbose compilation output (with -Wall and -v)

    g++ -v -Wall -o display_image display_image.cpp -I/usr/local/include -I/usr/local/include/opencv -L/usr/local/lib -lopencv_core -lopencv_highgui  
    Using built-in specs.
    COLLECT_GCC=g++
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
    COLLECT_GCC_OPTIONS='-v' '-Wall' '-o' 'display_image' '-I' '/usr/local/include' '-I' '/usr/local/include/opencv' '-L/usr/local/lib' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    /usr/lib/gcc/x86_64-linux-gnu/4.6/cc1plus -quiet -v -I /usr/local/include -I /usr/local/include/opencv -imultilib . -imultiarch x86_64-linux-gnu -D_GNU_SOURCE display_image.cpp -quiet -dumpbase display_image.cpp -mtune=generic -march=x86-64 -auxbase display_image -Wall -version -fstack-protector -o /tmp/ccDB7q8G.s
    GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
        compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
    ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
    ignoring duplicate directory "/usr/local/include"
      as it is a non-system directory that duplicates a system directory
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/include/opencv
     /usr/include/c++/4.6
     /usr/include/c++/4.6/x86_64-linux-gnu/.
     /usr/include/c++/4.6/backward
     /usr/lib/gcc/x86_64-linux-gnu/4.6/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
    End of search list.
    GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    Compiler executable checksum: 65b5171ac1bd7b3f07dbea6bdb24be3d
    COLLECT_GCC_OPTIONS='-v' '-Wall' '-o' 'display_image' '-I' '/usr/local/include' '-I' '/usr/local/include/opencv' '-L/usr/local/lib' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
     as --64 -o /tmp/cchdK0Uq.o /tmp/ccDB7q8G.s
    COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
    LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
    COLLECT_GCC_OPTIONS='-v' '-Wall' '-o' 'display_image' '-I' '/usr/local/include' '-I' '/usr/local/include/opencv' '-L/usr/local/lib' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-linux-gnu/4.6/collect2 --sysroot=/ --build-id --no-add-needed --as-needed --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o display_image /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/local/lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. /tmp/cchdK0Uq.o -lopencv_core -lopencv_highgui -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
    /tmp/cchdK0Uq.o: In function `main':
    display_image.cpp:(.text+0x9b): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    display_image.cpp:(.text+0x13f): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    display_image.cpp:(.text+0x1a1): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
    collect2: ld returned 1 exit status
    make: *** [display_image] Error 1
    

    解决方案

    My guess is that you are missing some *-dev packages. The tutorial lists a whole bunch of them right in the beginning, and in my experience usually those are the immediate causes of failed compilations. Unfortunately you can get an indirect message from the compiler. I guess the error message what you mention is just the tail of the build output, which can be far form the real cause. What you have to do is redirect the build output (with tee you can split it and see it on the console and get a build log too), or you already have a build log. Study that build log and look at the first or second error message which appears during the compilation. That can indicate the missing library or dev package better. This is just a guess, guideline. Provide us the whole build log. If the output is that short, try to increase output verbosity. Also, I might be totally wrong.

    I compared the Ubuntu 11.04 tutorial linked by @Gaurav Raj and your Ubuntu 12.04 tutorial. I'd try to install these packages:

    • libpng12-dev
    • libpng++-dev
    • libpng3
    • libpnglite-dev
    • libpngwriter0-dev
    • zlib1g-dbg
    • zlib1g-dev
    • pngtools
    • libjpeg8-dev
    • libjpeg8-dbg
    • libjpeg-progs
    • ffmpeg
    • libgstreamer0.xy-0-dbg (xy supposed to be a version for Ubuntu 12.04 this is probably newer version than 0.10 for Ubuntu 11.04)
    • libgstreamer0.xy-dev
    • libxine-dev
    • libunicap2-dev
    • swig
    • libdc1394-utils

    Before installing them, you can check if they installed by saying dpkg -l | grep ${pkg_name_to_check}.

    这篇关于OpenCV 2.4.1未定义的参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆