diff --git a/BMapBindings/PyBMap/.gitignore b/BMapBindings/PyBMap/.gitignore index 20e0a41..d6db128 100644 --- a/BMapBindings/PyBMap/.gitignore +++ b/BMapBindings/PyBMap/.gitignore @@ -1,6 +1,9 @@ # my ban *.dll *.pdb +*.so +*.dylib +*.bin testbench.py # Byte-compiled / optimized / DLL files diff --git a/BMapBindings/PyBMap/PyBMap/bmap.py b/BMapBindings/PyBMap/PyBMap/bmap.py index 466faf6..8dcab34 100644 --- a/BMapBindings/PyBMap/PyBMap/bmap.py +++ b/BMapBindings/PyBMap/PyBMap/bmap.py @@ -1,4 +1,4 @@ -import ctypes, os +import ctypes, os, sys #region Type Defines @@ -67,10 +67,21 @@ bm_VxMatrix_p = ctypes.POINTER(bm_VxMatrix) #region BMap Loader +_g_BMapLibName: str + +if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'): + _g_BMapLibName = "BMap.dll" +elif sys.platform.startswith('linux') or sys.platform.startswith('freebsd'): + _g_BMapLibName = "BMap.so" +elif sys.platform.startswith('darwin'): + _g_BMapLibName = "BMap.dylib" +else: + _g_BMapLibName = "BMap.bin" + _g_BMapModule: ctypes.CDLL = None try: _g_BMapModule = ctypes.cdll.LoadLibrary( - os.path.join(os.path.dirname(__file__), "BMap.dll") + os.path.join(os.path.dirname(__file__), _g_BMapLibName) ) except: _g_BMapModule = None diff --git a/BMapBindings/PyBMap/README.md b/BMapBindings/PyBMap/README.md index db6271e..7b7f12f 100644 --- a/BMapBindings/PyBMap/README.md +++ b/BMapBindings/PyBMap/README.md @@ -2,5 +2,5 @@ The real scripts are placed in sub PyBMap folder. This folder is served for testbench scripts placing. Place any testbench files (e.g. `testbench.py`) in there what you want and don't sumbit them. -The native BMap library should be placed in sub PyBMap folder, and I have used gitignore file to filter them. -The native BMap library must be named as `BMap.dll` in any platforms (e.g. Linux, macOS). Do not change name to `BMap.so` or `BMap.dylib`. +The native BMap library should be placed in sub PyBMap folder, and I have used gitignore file to filter them. +The native BMap library must be named as `BMap.dll` (in Windows), `BMap.so` (in Linux or BSD), or `BMap.dylib` (in macOS). If you still can not load BMap or your system is not listed above, you should name it as `BMap.bin`. diff --git a/CodeGen/BMapBindings/snippets/header.py b/CodeGen/BMapBindings/snippets/header.py index 97cdd1f..8a7e521 100644 --- a/CodeGen/BMapBindings/snippets/header.py +++ b/CodeGen/BMapBindings/snippets/header.py @@ -1,4 +1,4 @@ -import ctypes, os +import ctypes, os, sys #region Type Defines @@ -67,10 +67,21 @@ bm_VxMatrix_p = ctypes.POINTER(bm_VxMatrix) #region BMap Loader +_g_BMapLibName: str + +if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'): + _g_BMapLibName = "BMap.dll" +elif sys.platform.startswith('linux') or sys.platform.startswith('freebsd'): + _g_BMapLibName = "BMap.so" +elif sys.platform.startswith('darwin'): + _g_BMapLibName = "BMap.dylib" +else: + _g_BMapLibName = "BMap.bin" + _g_BMapModule: ctypes.CDLL = None try: _g_BMapModule = ctypes.cdll.LoadLibrary( - os.path.join(os.path.dirname(__file__), "BMap.dll") + os.path.join(os.path.dirname(__file__), _g_BMapLibName) ) except: _g_BMapModule = None