From 76ef7a9081b2316d82029db49e00343b1af9f30c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 27 Feb 2021 15:50:58 -0500 Subject: [PATCH] safer detection and load of lammps shared library --- python/lammps/core.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index e13bf9585b..eaf78dfa0c 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -121,18 +121,16 @@ class lammps(object): lib_ext = ".so" if not self.lib: - try: - if not name: - self.lib = CDLL(join(modpath,"liblammps" + lib_ext),RTLD_GLOBAL) + if name: + libpath = join(modpath,"liblammps_%s" % name + lib_ext) + else: + libpath = join(modpath,"liblammps" + lib_ext) + if not os.path.isfile(libpath): + if name: + libpath = "liblammps_%s" % name + lib_ext else: - self.lib = CDLL(join(modpath,"liblammps_%s" % name + lib_ext), - RTLD_GLOBAL) - except: - if not name: - self.lib = CDLL("liblammps" + lib_ext,RTLD_GLOBAL) - else: - self.lib = CDLL("liblammps_%s" % name + lib_ext,RTLD_GLOBAL) - + libpath = "liblammps" + lib_ext + self.lib = CDLL(libpath,RTLD_GLOBAL) # declare all argument and return types for all library methods here. # exceptions are where the arguments depend on certain conditions and