diff --git a/config/ompi_setup_java.m4 b/config/ompi_setup_java.m4 index bf707a89b17..2427f742bc9 100644 --- a/config/ompi_setup_java.m4 +++ b/config/ompi_setup_java.m4 @@ -74,10 +74,22 @@ AC_DEFUN([OMPI_SETUP_JAVA_BINDINGS],[ # header file needs this file, so we need to check for # it/include it in our sources when compiling on Mac). AC_CHECK_HEADERS([TargetConditionals.h]) + + # dladdr is required to build the full path to libmpi on OS X 10.11 aka El Capitan + # OPAL_CHECK_PACKAGE([mpi_java], [dlfcn.h], [dl], [dladdr], [], [], [], [OMPI_HAVE_DLADDR=1], [OMPI_HAVE_DLADDR=0]) + #AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + #[[Dl_info info; dladdr((void *)0, &info);]])], + #[OMPI_HAVE_DLADDR=1], + #[OMPI_HAVE_DLADDR=0]) + AC_CHECK_TYPE([Dl_info], [OMPI_HAVE_DLADDR=1], [OMPI_HAVE_DLADDR=0], [[#include ]]) + else AC_MSG_RESULT([no]) WANT_MPI_JAVA_SUPPORT=0 + OMPI_HAVE_DLADDR=0 fi + AC_DEFINE_UNQUOTED([OMPI_HAVE_DLADDR], [$OMPI_HAVE_DLADDR], + [do we have dladdr]) AC_DEFINE_UNQUOTED([OMPI_WANT_JAVA_BINDINGS], [$WANT_MPI_JAVA_SUPPORT], [do we want java mpi bindings]) AM_CONDITIONAL(OMPI_WANT_JAVA_BINDINGS, test "$WANT_MPI_JAVA_SUPPORT" = "1") diff --git a/ompi/mpi/java/c/Makefile.am b/ompi/mpi/java/c/Makefile.am index 95615ea41f8..a0a5c6ac980 100644 --- a/ompi/mpi/java/c/Makefile.am +++ b/ompi/mpi/java/c/Makefile.am @@ -1,9 +1,11 @@ # -*- makefile -*- # # Copyright (c) 2011-2013 Cisco Systems, Inc. All rights reserved. -# Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2015 Los Alamos National Security, LLC. All rights # reserved. +# Copyright (c) 2015 Research Organization for Information Science +# and Technology (RIST). All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -44,7 +46,7 @@ libmpi_java_la_SOURCES = \ mpi_Status.c \ mpi_Win.c -libmpi_java_la_LIBADD = $(top_builddir)/ompi/libmpi.la +libmpi_java_la_LIBADD = -ldl $(top_builddir)/ompi/libmpi.la libmpi_java_la_LDFLAGS = -version-info $(libmpi_java_so_version) endif diff --git a/ompi/mpi/java/c/mpi_MPI.c b/ompi/mpi/java/c/mpi_MPI.c index 5b3a39e1368..a8bb4c4b710 100644 --- a/ompi/mpi/java/c/mpi_MPI.c +++ b/ompi/mpi/java/c/mpi_MPI.c @@ -14,6 +14,8 @@ * reserved. * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015 Intel, Inc. All rights reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -64,6 +66,9 @@ #endif #include #include +#if HAVE_LIBGEN_H +#include +#endif #include "opal/util/output.h" #include "opal/datatype/opal_convertor.h" @@ -125,8 +130,26 @@ OBJ_CLASS_INSTANCE(ompi_java_buffer_t, jint JNI_OnLoad(JavaVM *vm, void *reserved) { libmpi = dlopen("libmpi." OPAL_DYN_LIB_SUFFIX, RTLD_NOW | RTLD_GLOBAL); - - if(libmpi == NULL) +#if OMPI_HAVE_DLADDR && HAVE_LIBGEN_H + /* + * OS X El Capitan does not propagate DYLD_LIBRARY_PATH to children any more + * so if previous dlopen failed, try to open libmpi in the same directory + * than the current libmpi_java + */ + if(NULL == libmpi) { + Dl_info info; + if(0 != dladdr((void *)JNI_OnLoad, &info)) { + char libmpipath[OPAL_PATH_MAX]; + char *libmpijavapath = strdup(info.dli_fname); + if (NULL != libmpijavapath) { + snprintf(libmpipath, OPAL_PATH_MAX-1, "%s/libmpi." OPAL_DYN_LIB_SUFFIX, dirname(libmpijavapath)); + free(libmpijavapath); + libmpi = dlopen(libmpipath, RTLD_NOW | RTLD_GLOBAL); + } + } + } +#endif + if(NULL == libmpi) { fprintf(stderr, "Java bindings failed to load libmpi: %s\n",dlerror()); exit(1);