Commit 0b426dad authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

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.
parent 63e71cd4
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -58,6 +58,13 @@ class lammps(object):
    # determine module location

    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.
    # e.g. if name = "g++", load liblammps_g++.so
@@ -66,7 +73,7 @@ class lammps(object):
    # does not need to be set for regular installations.
    # fall back to loading with a relative path, which typically
    # requires LD_LIBRARY_PATH to be set appropriately.

    if not self.lib:
      try:
        if not name: self.lib = CDLL(join(modpath,"liblammps.so"),RTLD_GLOBAL)
        else: self.lib = CDLL(join(modpath,"liblammps_%s.so" % name),RTLD_GLOBAL)