在Linux上加载多个相似的共享库 [英] loading multiple similar shared libraries on linux

查看:115
本文介绍了在Linux上加载多个相似的共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究创建模型的代码。一个模型是从一个XML文件创建的,并且它的一部分表示是随时生成的C代码。这个C代码被动态编译成共享库(使用POCO共享lib类)。共享库主要包含小函数,模型创建的一部分是填充这些函数的函数指针。所有这一切正常。但是,同时创建多个模型会导致问题。



我相信它与动态加载在Linux上的工作方式有关,并且每个共享库都包含具有相同名称的函数。 PIC是否导致这种情况?这些问题在任何意义上都不会从共享库函数中检索到数据。



所以问题是,如何加载包含相同函数名的多个(数千个)共享库Linux呢?

上面的工作在Windows上很好,看起来动态加载的库数据/函数保持完全隔离。

解决方案

Poco SharedLibrary打开函数接受链接器标志。缺省值是Poco :: SharedLibrary :: SHLIB_GLOBAL,对应于RTLO_LOCAL对应的dlopens RTLD_GLOBAL和Poco :: SharedLibrary :: SHLIB_LOCAL。有关详细信息,请参见 http://linux.die.net/man/3/dlopen 。 。



传递Poco :: SharedLibrary :: SHLIB_LOCAL标志解决了问题。


I am working on code that creates 'models'. A model is created from an XML file and part of its representation is, generated on the fly, C code. This C code is compiled, on the fly, into a shared library that is dynamically loaded (using POCO shared lib class). The shared library mainly contains small functions, and part of a models creation is to populate function pointers to these functions. All this works fine. However, creating several models, at the same time, causes problems.

I believe it has to do with how the dynamic loading works on Linux, and the fact that each shared library contain functions with identical names. Does PIC cause this? The problems manifest itself in no sense data being retrieved from shared libraries functions.

So question is, how to load multiple (thousands) shared libraries, containing identical function names, on linux?

The above works fine on windows, where it seems that dynamically loaded libraries data/functions are kept perfectly isolated from each other.

解决方案

Poco SharedLibrary open function accepts linker flags. Default is Poco::SharedLibrary::SHLIB_GLOBAL, corresponding to dlopens RTLD_GLOBAL and Poco::SharedLibrary::SHLIB_LOCAL, corresponding to RTLD_LOCAL. See http://linux.die.net/man/3/dlopen for more info.

Passing the Poco::SharedLibrary::SHLIB_LOCAL flag fixed the problem.

这篇关于在Linux上加载多个相似的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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