我有一个 C++ 库,我用 SWIG 包装它,以便在 python 中访问。据我了解(根据经验),当 SWIG 在 python 中包装 C++ 库时,加载时会将 C++ 库符号放置在“本地”范围中。也就是说,未来的动态链接库无法找到符号的范围。
(我从 man dlopen(3) 得到“本地”的定义)
是有没有办法让 SWIG 将这些符号放入“全局”范围,以便将来的任何动态链接库都可以找到它们?
I have a C++ library that I am wrapping with SWIG to make accessible in python. It is my understanding (from experience) that when SWIG wraps a C++ library in python, upon loading it places the C++ library symbols in a "local" scope. That is - a scope which does not enable future dynamically linked libraries to find the symbols.
(I'm getting this definition of "local" from man dlopen(3) )
Is there any way to get SWIG to place these symbols into the "global" scope, such that any future dynamically linked libraries can find them?
发布评论
评论(1)
您可以通过调用 RTLD_GLOBAL 标志创建 python
dlopen
共享对象。 setdlopenflags" rel="nofollow">setdlopenflags
在sys
中,例如:在加载模块之前。 (有一个 关于 swig-users 的讨论)
You can make python
dlopen
shared objects with theRTLD_GLOBAL
flag by callingsetdlopenflags
insys
, e.g.:before your module is loaded. (There's a discussion on swig-users about this)