From: John P. <jo...@cu...> - 2006-12-21 05:29:05
|
Josh Cherry wrote: > On Tue, 19 Dec 2006, Geoffrey Hutchison wrote: > > >> One thing we discovered when writing the Perl and Python bindings >> with SWIG was that these internal dlopen() calls broke unless we >> hacked the SWIG output to add something like this: >> import sys >> if sys.platform.find(\"linux\") != -1: >> import dl >> sys.setdlopenflags(sys.getdlopenflags() | dl.RTLD_GLOBAL) >> >> >> Now I don't code on Linux, so it's hard for me to test these things. >> I don't know if the problem is that our C++ library should be calling >> RTLD_LAZY|RTLD_GLOBAL when it loads the format shared objects. >> >> -or- >> >> That we need some way to set the options when the SWIG interfaces >> load our library. >> > > I ran into this issue when doing multiple modules. My understanding is > that sys.setdlopenflags only affects what flags Python uses when it does a > dlopen, such as the one it does when you import a shared library. I don't > think Python could affect what your C++ library does if it wanted to. So > I think the second possibility is correct. The first might come up as an > issue, but it wouldn't be fixed by the setdlopenflags. > My understanding of this problem was that you need to tell Python to use that dlopen mode, as doing so means that symbols in your SWIG .so file are shared with any .so files dlopened *from inside* your SWIG .so file. So you mentioned used 'format shared objects' which I presume are .so files that are opened from inside your SWIG .so file. If those format shared objects contains references to symbols in the SWIG .so file, then Python needs to have opened your SWIG .so file using the correct dlopen flags as above. My result was to add the following code before importing my python wrapper for the SWIG module (although your idea of putting this code at the head of the python wrapper is better): if platform.system() != "Windows": import dl # This sets the flags for dlopen used by python so that the symbols in the # ascend library are made available to libraries dlopened within ASCEND: sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_NOW) print_loading_status("Loading LIBASCEND/ascpy") import ascpy If anyone can offer more clarity on this, please do. Cheers JP |