do not require the LAMMPS shared library when loading the python wrapper from inside LAMMPS
Thanks to Giacomo Fiorin for figuring this out with NAMD/Colvars. This requires linking with -Xlinker -export-dynamic or equivalent, which is the default when using python-config to provide linker flags. We will fall back to loading the DSO in case the initial load fails.
This commit is contained in:
@ -58,6 +58,13 @@ class lammps(object):
|
|||||||
# determine module location
|
# determine module location
|
||||||
|
|
||||||
modpath = dirname(abspath(getsourcefile(lambda:0)))
|
modpath = dirname(abspath(getsourcefile(lambda:0)))
|
||||||
|
self.lib = None
|
||||||
|
|
||||||
|
# if a pointer to a LAMMPS object is handed in, all symbols should already be available.
|
||||||
|
try:
|
||||||
|
if ptr: self.lib = CDLL("",RTLD_GLOBAL)
|
||||||
|
except:
|
||||||
|
self.lib = None
|
||||||
|
|
||||||
# load liblammps.so unless name is given.
|
# load liblammps.so unless name is given.
|
||||||
# e.g. if name = "g++", load liblammps_g++.so
|
# e.g. if name = "g++", load liblammps_g++.so
|
||||||
@ -66,13 +73,13 @@ class lammps(object):
|
|||||||
# does not need to be set for regular installations.
|
# does not need to be set for regular installations.
|
||||||
# fall back to loading with a relative path, which typically
|
# fall back to loading with a relative path, which typically
|
||||||
# requires LD_LIBRARY_PATH to be set appropriately.
|
# requires LD_LIBRARY_PATH to be set appropriately.
|
||||||
|
if not self.lib:
|
||||||
try:
|
try:
|
||||||
if not name: self.lib = CDLL(join(modpath,"liblammps.so"),RTLD_GLOBAL)
|
if not name: self.lib = CDLL(join(modpath,"liblammps.so"),RTLD_GLOBAL)
|
||||||
else: self.lib = CDLL(join(modpath,"liblammps_%s.so" % name),RTLD_GLOBAL)
|
else: self.lib = CDLL(join(modpath,"liblammps_%s.so" % name),RTLD_GLOBAL)
|
||||||
except:
|
except:
|
||||||
if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL)
|
if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL)
|
||||||
else: self.lib = CDLL("liblammps_%s.so" % name,RTLD_GLOBAL)
|
else: self.lib = CDLL("liblammps_%s.so" % name,RTLD_GLOBAL)
|
||||||
|
|
||||||
# if no ptr provided, create an instance of LAMMPS
|
# if no ptr provided, create an instance of LAMMPS
|
||||||
# don't know how to pass an MPI communicator from PyPar
|
# don't know how to pass an MPI communicator from PyPar
|
||||||
|
|||||||
Reference in New Issue
Block a user