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

L

liam_herron

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?

Regards,
Liam
 
R

Roman Yakovenko

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top