From 88488fdbb9d915e8cc166fd620fcd4c2fe4bd1f1 Mon Sep 17 00:00:00 2001 From: Sergei Lebedev Date: Thu, 29 Jun 2017 01:50:50 +0200 Subject: [PATCH] Fixed shared library loading in the Python package (#2461) * Fixed DLL name on Windows in ``xgboost.libpath`` * Added support for OS X to ``xgboost.libpath`` * Use .dylib for shared library on OS X This does not affect the JNI library, because it is not trully cross-platform in the Makefile-build anyway. --- Makefile | 13 ++++++++----- python-package/xgboost/libpath.py | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 055b76611..56ef7a4ad 100644 --- a/Makefile +++ b/Makefile @@ -67,12 +67,15 @@ ifndef LINT_LANG LINT_LANG= "all" endif -ifneq ($(UNAME), Windows) - CFLAGS += -fPIC - XGBOOST_DYLIB = lib/libxgboost.so -else +ifeq ($(UNAME), Windows) XGBOOST_DYLIB = lib/libxgboost.dll JAVAINCFLAGS += -I${JAVA_HOME}/include/win32 +else ifeq ($(UNAME), Darwin) + XGBOOST_DYLIB = lib/libxgboost.dylib + CFLAGS += -fPIC +else + XGBOOST_DYLIB = lib/libxgboost.so + CFLAGS += -fPIC endif ifeq ($(UNAME), Linux) @@ -162,7 +165,7 @@ lib/libxgboost.a: $(ALL_DEP) @mkdir -p $(@D) ar crv $@ $(filter %.o, $?) -lib/libxgboost.dll lib/libxgboost.so: $(ALL_DEP) +lib/libxgboost.dll lib/libxgboost.so lib/libxgboost.dylib: $(ALL_DEP) @mkdir -p $(@D) $(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %a, $^) $(LDFLAGS) diff --git a/python-package/xgboost/libpath.py b/python-package/xgboost/libpath.py index 46d200473..6abb9ad7b 100644 --- a/python-package/xgboost/libpath.py +++ b/python-package/xgboost/libpath.py @@ -24,7 +24,7 @@ def find_lib_path(): dll_path = [curr_path, os.path.join(curr_path, '../../lib/'), os.path.join(curr_path, './lib/'), os.path.join(sys.prefix, 'xgboost')] - if os.name == 'nt': + if sys.platform == 'win32': if platform.architecture()[0] == '64bit': dll_path.append(os.path.join(curr_path, '../../windows/x64/Release/')) # hack for pip installation when copy all parent source directory here @@ -33,9 +33,12 @@ def find_lib_path(): dll_path.append(os.path.join(curr_path, '../../windows/Release/')) # hack for pip installation when copy all parent source directory here dll_path.append(os.path.join(curr_path, './windows/Release/')) - dll_path = [os.path.join(p, 'libxgboost.dll') for p in dll_path] - else: + dll_path = [os.path.join(p, 'xgboost.dll') for p in dll_path] + elif sys.platform.startswith('linux'): dll_path = [os.path.join(p, 'libxgboost.so') for p in dll_path] + elif sys.platform == 'darwin': + dll_path = [os.path.join(p, 'libxgboost.dylib') for p in dll_path] + lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)] # From github issues, most of installation errors come from machines w/o compilers