Problem Dynamic Loading Linux C++ .so module using python2.4

Roman Yakovenko roman.yakovenko at gmail.com
Mon Apr 10 15:52:13 EDT 2006


On 10 Apr 2006 12:42:28 -0700, liam_herron <liam_herron at hotmail.com> wrote:
> I have compiled my boost-enabled C++ module and have it working when I
> explicity set my LD_LIBRARY_PATH before invoking the python2.4
> interpreter.  Now I don't want everyone to have to set this environment
> variable so I would like to devise a way that the module can load
> itself.  My attempt was to create a module folder with the following
> __init__.py:
>
> -=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> import os
> import sys
>
> my_path = os.path.dirname(os.path.abspath(__file__))
> mylib_path = os.path.join(my_path, 'subdirOfSitePackages')
>
> if sys.platform == 'win32':
>     # Windows needs DLLs on the %PATH%.
>     os.environ['PATH'] = os.environ['PATH'] + ";" + my_path
> else:
>     # LINUX
>     if os.environ.has_key('LD_LIBRARY_PATH'):
>         os.environ['LD_LIBRARY_PATH'] = mylib_path + ":" +
> os.environ['LD_LIBRARY_PATH']
>     else:
>       os.environ['LD_LIBRARY_PATH'] = mylib_path
>
> from myLibFolder._mylib import *
>
> -=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> On my filesystem I have the following folder:
>
> /usr/lib/python2.4/site-packages/myLibFolder
>
> With the following files:
> __init__.py
> _mylib.so
> mylibDBAccess.so
> mylibCommon.so
> libboost_python.so
>
> Where _mylib.so dynamically links with mylibDBAccess.so,
> mylibCommon.so, libboost_python.so.
>
> When I try to import this Folder in python2.4, it actually complains
> about the subsequent dynamic linking of the .so files (ie
> mylibDBAccess.so).
>
> Any ideas on how to resolve this?

I think you can not. I can not find the article, but I read that changes of
LD_LIBRARY_PATH after program start, does not have any effects, because this
variable is read only once - at program launching.

I think small shell script will help you.

> Regards,
> Liam
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Python-list mailing list