From d0ef4c71030d16012f1b6766bd92f950be2ebc33 Mon Sep 17 00:00:00 2001 From: Manuel Guenther <manuel.guenther@idiap.ch> Date: Wed, 20 Aug 2014 20:05:54 +0200 Subject: [PATCH] Added function to load the C++ Library in a given bob module. --- bob/extension/__init__.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bob/extension/__init__.py b/bob/extension/__init__.py index 55e1cfc..5b1bac6 100644 --- a/bob/extension/__init__.py +++ b/bob/extension/__init__.py @@ -191,7 +191,36 @@ def get_bob_libraries(bob_packages): return includes, libraries, library_directories +def load_bob_library(name, _file_, version=None): + """Loads the bob Library for the given package name in the given version (if given). + The _file_ parameter is expected to be the ``__file__`` member of the main ``__init__.py`` of the package. + It is used to determine the directory, where the library should be loaded from. + Keyword parameters + + name : string + The name of the bob package to load the library from, e.g. ``bob.core`` + + _file_ : string + The ``__file__`` member of the ``__init__.py`` file in which the library is loaded. + + version : string + The version of the library to load. Can be usually omitted. + """ + + libname = 'lib' + name.replace('.', '_') + if sys.platform == 'darwin': + libname += ('.' + version if version is not None else '') + '.dylib' + elif sys.platform == 'win32': + libname += '.dll' + ('.' + version if version is not None else '') + else: # linux like + libname += '.so' + ('.' + version if version is not None else '') + + full_libname = os.path.join(os.path.dirname(_file_), libname) + + import ctypes + print "loading library", full_libname + ctypes.cdll.LoadLibrary(full_libname) class Extension(DistutilsExtension): -- GitLab