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.
This commit is contained in:
Sergei Lebedev 2017-06-29 01:50:50 +02:00 committed by Rory Mitchell
parent 2911597f3d
commit 88488fdbb9
2 changed files with 14 additions and 8 deletions

View File

@ -67,12 +67,15 @@ ifndef LINT_LANG
LINT_LANG= "all" LINT_LANG= "all"
endif endif
ifneq ($(UNAME), Windows) ifeq ($(UNAME), Windows)
CFLAGS += -fPIC
XGBOOST_DYLIB = lib/libxgboost.so
else
XGBOOST_DYLIB = lib/libxgboost.dll XGBOOST_DYLIB = lib/libxgboost.dll
JAVAINCFLAGS += -I${JAVA_HOME}/include/win32 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 endif
ifeq ($(UNAME), Linux) ifeq ($(UNAME), Linux)
@ -162,7 +165,7 @@ lib/libxgboost.a: $(ALL_DEP)
@mkdir -p $(@D) @mkdir -p $(@D)
ar crv $@ $(filter %.o, $?) 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) @mkdir -p $(@D)
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %a, $^) $(LDFLAGS) $(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %a, $^) $(LDFLAGS)

View File

@ -24,7 +24,7 @@ def find_lib_path():
dll_path = [curr_path, os.path.join(curr_path, '../../lib/'), dll_path = [curr_path, os.path.join(curr_path, '../../lib/'),
os.path.join(curr_path, './lib/'), os.path.join(curr_path, './lib/'),
os.path.join(sys.prefix, 'xgboost')] os.path.join(sys.prefix, 'xgboost')]
if os.name == 'nt': if sys.platform == 'win32':
if platform.architecture()[0] == '64bit': if platform.architecture()[0] == '64bit':
dll_path.append(os.path.join(curr_path, '../../windows/x64/Release/')) dll_path.append(os.path.join(curr_path, '../../windows/x64/Release/'))
# hack for pip installation when copy all parent source directory here # 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/')) dll_path.append(os.path.join(curr_path, '../../windows/Release/'))
# hack for pip installation when copy all parent source directory here # hack for pip installation when copy all parent source directory here
dll_path.append(os.path.join(curr_path, './windows/Release/')) dll_path.append(os.path.join(curr_path, './windows/Release/'))
dll_path = [os.path.join(p, 'libxgboost.dll') for p in dll_path] dll_path = [os.path.join(p, 'xgboost.dll') for p in dll_path]
else: elif sys.platform.startswith('linux'):
dll_path = [os.path.join(p, 'libxgboost.so') for p in dll_path] 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)] 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 # From github issues, most of installation errors come from machines w/o compilers