find LAMMPS shared object location for ctypes loading from introspection

This commit is contained in:
Axel Kohlmeyer
2015-06-29 15:02:37 -04:00
parent 6b8b7c14a6
commit 567d5a49cf
2 changed files with 15 additions and 31 deletions

View File

@ -15,17 +15,21 @@
import sys,traceback,types
from ctypes import *
import os.path
from os.path import dirname,abspath,join
from inspect import getsourcefile
class lammps:
def __init__(self,name="",cmdargs=None,ptr=None):
# determine module location
modpath = dirname(abspath(getsourcefile(lambda:0)))
# load liblammps.so by default
# if name = "g++", load liblammps_g++.so
try:
if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL)
else: self.lib = CDLL("liblammps_%s.so" % name,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)
except:
type,value,tb = sys.exc_info()
traceback.print_exception(type,value,tb)