静态和共享库符号冲突? [英] Static and shared library symbol conflicts?

查看:406
本文介绍了静态和共享库符号冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目正在使用FreeImage和openCV,目前我们使用jpeg支持从这两个(我正在努力修复,但现在它必须留下来)。无论如何,FreeImage将libjpeg 7.0编译成其静态库,而openCV的highgui库将其链接为一个共享库(在我的系统上,Ubuntu 9,我安装了libjpeg 6.2)。

I've got a project working on that's using FreeImage and openCV, currently we're using the jpeg support from both of these (I am working towards fixing that, but for now it's got to stay). Anyhow, FreeImage compiles libjpeg 7.0 into its static libraries, and openCV's highgui library links it in as a shared library (on my system, Ubuntu 9, I've got libjpeg 6.2 installed).

它们链接到最终的库,用于链接到各种程序,java包装等。所有这些工作正常,没有符号冲突或任何在编译/链接时间。然而,当我使用openCV cvLoadImage函数打开一个图像时,它读取标题时死掉,这很可能是由于6.2和7.0中的标题之间的差异。

They link into a final library that's used to link into various programs, java wrappers, etc. All of that works fine, no symbol conflicts or anything during compile/link time. However, when I go to open an image using the openCV cvLoadImage function, it dies when reading the header, most likely due to differences between headers in 6.2 and 7.0.

如果我取消链接FreeImage(并注释掉需要它的代码),openCV调用再次开始工作,所以FreeImage的静态libjpeg符号与符号冲突将从libjpeg共享库加载。我不能弄清楚的是为什么我的编译器不会在连接期间抛出一个错误,因为两组libjpeg符号。此外,我已经尝试临时替换我的系统的jpeglib.h标头与7.0版本,看看openCV编译的是否会与freeimage带来的表,同步符号,似乎没有什么效果。

If I unlink FreeImage (and comment out the code that requires it), the openCV calls start working again, so clearly the static libjpeg symbols from FreeImage are conflicting with symbols that would be loaded from the libjpeg shared library. What I can't figure out is why my compiler isn't throwing an error during linking because of the two sets of libjpeg symbols. Additionally, I've tried replacing my system's jpeglib.h header with the 7.0 version temporarily to see if openCV compiled with that would then sync up with the symbols that freeimage brings to the table, to no avail it seems.

最后,我把一个printf放在libjpeg的jpeg_read_header中,freeimage编译,并重建它,看看openCV是否使用freeimage libjpeg定义。

Lastly I put a printf in jpeg_read_header in the libjpeg that freeimage compiles, and rebuilt it to see if openCV is using the freeimage libjpeg definition. It didn't print out so I have to assume not.

所以我想我的问题是

1 )为什么不链接静态libjpeg和共享libjpeg会由于重复符号而产生链接错误?

1) Why doesn't linking a static libjpeg and a shared libjpeg generate linking errors due to duplicate symbols?

2)有人知道为什么这两个东西彼此冲突?

2) Does anyone know why these two things are conflicting with one another?

编辑:在调试模式下编译openCV,然后在正常模式下再次似乎敲了一些松散的东西,使它再次工作,不知道发生了什么。 >

Compiling openCV in debug mode and then in regular mode again seems to have knocked something loose and made it work again, no idea what's going on.

推荐答案

您需要修改链接选项以仅导出所需的符号,然后冲突中的所有符号将在静态链接,那么没有冲突。默认情况下,所有的符号都被导出,这就是问题所在。请参阅以下链接: http:// www .gnu.org / software / gnulib / manual / html_node / Exported-Symbols-of-Shared-Libraries.html

You need to modify the linking options to export only the symbols that you want, then all the symbols in conflict will be hidden internally in the static linking, then no conflicts. By default all the symbols are exported, that's the problem. See this link: http://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html

这篇关于静态和共享库符号冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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