在Ubuntu 11.10上编译OpenCV2.3.1时,出现链接器错误 [英] Strange linker error while compiling OpenCV2.3.1 on Ubuntu 11.10

查看:1305
本文介绍了在Ubuntu 11.10上编译OpenCV2.3.1时,出现链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Ubuntu 11.10上按照这里中的说明编译OpenCV版本2.3.1。我收到以下错误。不能理解发生了什么... /usr/local/lib/libavcodec.a 存在,但链接器无法链接到它,或其他?



错误:

  [20%]内置目标pch_Generate_opencv_highgui 
链接CXX共享库../../lib/libopencv_highgui.so
/ usr / bin / ld:/usr/local/lib/libavcodec.a(avpacket.o):重定位R_X86_64_32S针对`av_destruct_packet'
在创建共享对象时不能使用;重新编译-fPIC
/usr/local/lib/libavcodec.a:无法读取符号:错误值
collect2:ld返回1退出状态


解决方案

问题是你试图链接 libopencv_highgui.so libavcodec.a 。后者是从没有 -fPIC (这是很常见)编译的代码构建的,并且这样的代码不能链接到共享库上 x86_64



您的选择是:




  • 获得 libavcodec.so 并安排链接到它

  • 删除 libavcodec code> -lavcodec



只需安装 libavcodec-dev 包。



<如果你是第二个,你仍然需要安排符号 libopencv_highgui.so 需要 libavcodec 到在运行时可用。您可以通过将主可执行文件与 libavcodec (归档或共享变体)链接来实现。


I'm trying to compile OpenCV version 2.3.1 on an Ubuntu 11.10 following instructions described here. I'm getting following error. Can't understand what is happening... /usr/local/lib/libavcodec.a exists but linker can't link against it, or something else?

error:

[ 20%] Built target pch_Generate_opencv_highgui
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet' 
can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

解决方案

The problem is that you are attempting to link libopencv_highgui.so with libavcodec.a. The latter is built from code compiled without -fPIC (which is quite usual), and such code can not be linked into shared libraries on x86_64.

Your choices are:

  • Obtain libavcodec.so and arrange to link against it, or
  • Remove libavcodec or -lavcodec from the link line completely.

For the first, you most likely just need to install libavcodec-dev package.

If you do the second, you will still have to arrange for symbols that libopencv_highgui.so needs from libavcodec to be available at runtime. You can achieve that by linking the main executable with libavcodec (either archive or shared variant).

这篇关于在Ubuntu 11.10上编译OpenCV2.3.1时,出现链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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