HDFS-17636. Don't add declspec for Windows (#7096)
* Windows doesn't want the macro _JNI_IMPORT_OR_EXPORT_ to be defined in the function definition. It fails to compile with the following error - "definition of dllimport function not allowed". * However, Linux needs it. Hence, we're going to add this macro based on the OS. * Also, we'll be compiling the `hdfs` target as an object library so that we can avoid linking to `jvm` library for `get_jni_test` target.
This commit is contained in:
parent
09b348753f
commit
d1ce965645
@ -32,13 +32,23 @@ include_directories(
|
|||||||
../libhdfspp/lib
|
../libhdfspp/lib
|
||||||
)
|
)
|
||||||
|
|
||||||
hadoop_add_dual_library(hdfs
|
set(HDFS_SOURCES
|
||||||
exception.c
|
exception.c
|
||||||
jni_helper.c
|
jni_helper.c
|
||||||
hdfs.c
|
hdfs.c
|
||||||
jclasses.c
|
jclasses.c
|
||||||
${OS_DIR}/mutexes.c
|
${OS_DIR}/mutexes.c
|
||||||
${OS_DIR}/thread_local_storage.c
|
${OS_DIR}/thread_local_storage.c
|
||||||
|
)
|
||||||
|
# We want to create an object library for hdfs
|
||||||
|
# so that we can reuse it for the targets
|
||||||
|
# (like get_jni_test), where we don't wish to
|
||||||
|
# link to hdfs's publicly linked libraries
|
||||||
|
# (like jvm)
|
||||||
|
add_library(hdfs_obj OBJECT ${HDFS_SOURCES})
|
||||||
|
set_target_properties(hdfs_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
|
hadoop_add_dual_library(hdfs
|
||||||
|
$<TARGET_OBJECTS:hdfs_obj>
|
||||||
$<TARGET_OBJECTS:x_platform_obj>
|
$<TARGET_OBJECTS:x_platform_obj>
|
||||||
$<TARGET_OBJECTS:x_platform_obj_c_api>
|
$<TARGET_OBJECTS:x_platform_obj_c_api>
|
||||||
)
|
)
|
||||||
|
@ -74,8 +74,19 @@ add_executable(uri_test uri_test.cc)
|
|||||||
target_link_libraries(uri_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(uri_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
|
||||||
add_memcheck_test(uri uri_test)
|
add_memcheck_test(uri uri_test)
|
||||||
|
|
||||||
|
# We want to link to all the libraries of hdfs_static library,
|
||||||
|
# except jvm.lib since we want to override some of the functions
|
||||||
|
# provided by jvm.lib.
|
||||||
|
get_target_property(HDFS_STATIC_LIBS_NO_JVM hdfs_static LINK_LIBRARIES)
|
||||||
|
list(REMOVE_ITEM HDFS_STATIC_LIBS_NO_JVM ${JAVA_JVM_LIBRARY})
|
||||||
add_executable(get_jni_test libhdfs_getjni_test.cc)
|
add_executable(get_jni_test libhdfs_getjni_test.cc)
|
||||||
target_link_libraries(get_jni_test gmock_main hdfs_static ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(get_jni_test
|
||||||
|
gmock_main
|
||||||
|
$<TARGET_OBJECTS:hdfs_obj>
|
||||||
|
$<TARGET_OBJECTS:x_platform_obj>
|
||||||
|
$<TARGET_OBJECTS:x_platform_obj_c_api>
|
||||||
|
${HDFS_STATIC_LIBS_NO_JVM}
|
||||||
|
${CMAKE_THREAD_LIBS_INIT})
|
||||||
add_memcheck_test(get_jni get_jni_test)
|
add_memcheck_test(get_jni get_jni_test)
|
||||||
|
|
||||||
add_executable(remote_block_reader_test remote_block_reader_test.cc)
|
add_executable(remote_block_reader_test remote_block_reader_test.cc)
|
||||||
|
@ -20,13 +20,26 @@
|
|||||||
#include <hdfs/hdfs.h>
|
#include <hdfs/hdfs.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DECLSPEC
|
||||||
|
#else
|
||||||
|
// Windows cribs when this is declared in the function definition,
|
||||||
|
// However, Linux needs it.
|
||||||
|
#define DECLSPEC _JNI_IMPORT_OR_EXPORT_
|
||||||
|
#endif
|
||||||
|
|
||||||
// hook the jvm runtime function. expect always failure
|
// hook the jvm runtime function. expect always failure
|
||||||
_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void*) {
|
DECLSPEC jint JNICALL JNI_GetDefaultJavaVMInitArgs(void*) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook the jvm runtime function. expect always failure
|
// hook the jvm runtime function. expect always failure
|
||||||
_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM**, void**, void*) {
|
DECLSPEC jint JNICALL JNI_CreateJavaVM(JavaVM**, void**, void*) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hook the jvm runtime function. expect always failure
|
||||||
|
DECLSPEC jint JNICALL JNI_GetCreatedJavaVMs(JavaVM**, jsize, jsize*) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user