From 3820ab6a0ba5adc67d3b12c4fc602f010f148dc5 Mon Sep 17 00:00:00 2001 From: Sergei Lebedev Date: Fri, 9 Jun 2017 17:25:09 +0200 Subject: [PATCH] [jvm-packages] Minor improvements to the CMake build (#2379) * [jvm-packages] Fixed JNI_OnLoad overload It does not compile on Windows without proper export flags. * [jvm-packages] Use JNI types directly where appropriate * Removed lib hack from CMake build Prior to this commit the CMake build use hardcoded lib prefix for libxgboost and libxgboost4j. Unfortunatelly this did not play well with Windows, which does not use the lib- prefix. --- CMakeLists.txt | 13 ++++++------- jvm-packages/xgboost4j/src/native/xgboost4j.cpp | 10 +++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e69aa44b..a44cbe0ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,8 +94,6 @@ if(MSVC) else() set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}) - #Prevent shared library being called liblibxgboost.so on Linux - set(CMAKE_SHARED_LIBRARY_PREFIX "") endif() set(LINK_LIBRARIES dmlccore rabit) @@ -124,11 +122,12 @@ endif() add_library(objxgboost OBJECT ${SOURCES}) set_target_properties(${objxgboost} PROPERTIES POSITION_INDEPENDENT_CODE 1) -add_library(libxgboost SHARED $ ${CUDA_OBJS}) -add_executable(xgboost $ ${CUDA_OBJS}) +add_executable(runxgboost $ ${CUDA_OBJS}) +set_target_properties(runxgboost PROPERTIES OUTPUT_NAME xgboost) +target_link_libraries(runxgboost ${LINK_LIBRARIES}) +add_library(xgboost SHARED $ ${CUDA_OBJS}) target_link_libraries(xgboost ${LINK_LIBRARIES}) -target_link_libraries(libxgboost ${LINK_LIBRARIES}) option(JVM_BINDINGS "Build JVM bindings" OFF) @@ -137,11 +136,11 @@ if(JVM_BINDINGS) include_directories(${JNI_INCLUDE_DIRS} jvm-packages/xgboost4j/src/native) - add_library(libxgboost4j SHARED + add_library(xgboost4j SHARED $ ${CUDA_OBJS} jvm-packages/xgboost4j/src/native/xgboost4j.cpp) - target_link_libraries(libxgboost4j + target_link_libraries(xgboost4j ${LINK_LIBRARIES} ${JNI_LIBRARIES}) endif() diff --git a/jvm-packages/xgboost4j/src/native/xgboost4j.cpp b/jvm-packages/xgboost4j/src/native/xgboost4j.cpp index bfd302ef1..eb2ce129f 100644 --- a/jvm-packages/xgboost4j/src/native/xgboost4j.cpp +++ b/jvm-packages/xgboost4j/src/native/xgboost4j.cpp @@ -24,11 +24,7 @@ // helper functions // set handle void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) { -#ifdef __APPLE__ - jlong out = (long) handle; -#else - int64_t out = (int64_t) handle; -#endif + jlong out = (jlong) handle; jenv->SetLongArrayRegion(jhandle, 0, 1, &out); } @@ -36,7 +32,7 @@ void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) { static JavaVM* global_jvm = nullptr; // overrides JNI on load -jint JNI_OnLoad(JavaVM *vm, void *reserved) { +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { global_jvm = vm; return JNI_VERSION_1_6; } @@ -76,7 +72,7 @@ XGB_EXTERN_C int XGBoost4jCallbackDataIterNext( batch, jenv->GetFieldID(batchClass, "featureValue", "[F")); XGBoostBatchCSR cbatch; cbatch.size = jenv->GetArrayLength(joffset) - 1; - cbatch.offset = reinterpret_cast( + cbatch.offset = reinterpret_cast( jenv->GetLongArrayElements(joffset, 0)); if (jlabel != nullptr) { cbatch.label = jenv->GetFloatArrayElements(jlabel, 0);