* configure.ac (AC_CHECK_ENABLE_LTDL): Removed.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 12 Jun 2008 13:32:04 +0000 (15:32 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 12 Jun 2008 13:32:04 +0000 (15:32 +0200)
(AC_CHECK_ENABLE_DL): Added.
* m4/ltdl.m4: Removed.
* m4/dl.m4: New file.

* src/cacao/cacao.c [ENABLE_LIBJVM] (ltdl.h): Removed.
(vmcore/system.h): Added.
(LIBJVM_NAME): New define.
(main): Use system_dl* functions.

* src/native/native.c: Replaced ltdl stuff with sytem_dl* stuff.
* src/native/native.h (NATIVE_LIBRARY_PREFIX): New define.
(NATIVE_LIBRARY_SUFFIX): Likewise.

* src/native/vm/gnuclasspath/java_lang_VMRuntime.c (mapLibraryName):
Use NATIVE_LIBRARY_* defines.

* src/vmcore/system.h [HAVE_DLFCN_H] (dlfcn.h): Added.
(system_dlclose): New function.
(system_dlerror): Likewise.
(system_dlopen): Likewise.
(system_dlsym): Likewise.

configure.ac
m4/dl.m4 [new file with mode: 0644]
m4/ltdl.m4 [deleted file]
src/cacao/cacao.c
src/native/native.c
src/native/native.h
src/native/vm/gnuclasspath/java_lang_VMRuntime.c
src/vmcore/system.h

index f4269984191652bb532c79376f54f59c80adc4d2..7af46bda55d855de7c1945fe759b13b1f1458b8b 100644 (file)
@@ -259,7 +259,6 @@ AC_STRUCT_TM
 
 dnl Checks for libraries (NOTE: Should be done before function checks,
 dnl as some functions may be in libraries we check for).
-AC_CHECK_LIB(dl, dlopen,,)
 
 dnl Checks for library functions.
 AC_PROG_GCC_TRADITIONAL
@@ -359,8 +358,7 @@ AC_DEFINE_UNQUOTED([CACAO_LIBDIR], "${CACAO_LIBDIR}", [library installation pref
 AC_SUBST(CACAO_LIBDIR)
 
 
-AC_CHECK_ENABLE_LTDL
-
+AC_CHECK_ENABLE_DL
 AC_CHECK_ENABLE_JAVA
 
 AC_CHECK_ENABLE_JIT
diff --git a/m4/dl.m4 b/m4/dl.m4
new file mode 100644 (file)
index 0000000..1dcc4e4
--- /dev/null
+++ b/m4/dl.m4
@@ -0,0 +1,46 @@
+dnl m4/dl.m4
+dnl
+dnl Copyright (C) 2008
+dnl CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+dnl 
+dnl This file is part of CACAO.
+dnl 
+dnl This program is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU General Public License as
+dnl published by the Free Software Foundation; either version 2, or (at
+dnl your option) any later version.
+dnl 
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl General Public License for more details.
+dnl 
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+
+
+dnl check if dynamic library loading should be used
+
+AC_DEFUN([AC_CHECK_ENABLE_DL],[
+AC_MSG_CHECKING(whether to support dynamic library loading)
+AC_ARG_ENABLE([dl],
+              [AS_HELP_STRING(--disable-dl,disable dynamic library loading (needs libdl) [[default=enabled]])],
+              [case "${enableval}" in
+                  no) ENABLE_DL=no;;
+                  *) ENABLE_DL=yes;;
+               esac],
+              [ENABLE_DL=yes])
+AC_MSG_RESULT(${ENABLE_DL})
+
+if test x"${ENABLE_DL}" = "xyes"; then
+    AC_CHECK_HEADERS([dlfcn.h],, [AC_MSG_ERROR(cannot find dlfcn.h)])
+    AC_CHECK_LIB([dl], [dlopen],, [AC_MSG_ERROR(cannot find libdl)])
+    AC_CHECK_FUNCS([dlclose])
+    AC_CHECK_FUNCS([dlerror])
+    AC_CHECK_FUNCS([dlopen])
+    AC_CHECK_FUNCS([dlsym])
+    AC_DEFINE([ENABLE_DL], 1, [Enable dynamic library loading.])
+fi
+])
diff --git a/m4/ltdl.m4 b/m4/ltdl.m4
deleted file mode 100644 (file)
index 6a7b174..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-dnl m4/ltdl.m4
-dnl
-dnl Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
-dnl C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-dnl E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-dnl J. Wenninger, Institut f. Computersprachen - TU Wien
-dnl 
-dnl This file is part of CACAO.
-dnl 
-dnl This program is free software; you can redistribute it and/or
-dnl modify it under the terms of the GNU General Public License as
-dnl published by the Free Software Foundation; either version 2, or (at
-dnl your option) any later version.
-dnl 
-dnl This program is distributed in the hope that it will be useful, but
-dnl WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-dnl General Public License for more details.
-dnl 
-dnl You should have received a copy of the GNU General Public License
-dnl along with this program; if not, write to the Free Software
-dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-dnl 02110-1301, USA.
-
-
-dnl check if ltdl should be used
-
-AC_DEFUN([AC_CHECK_ENABLE_LTDL],[
-AC_MSG_CHECKING(whether ltdl should be used)
-AC_ARG_ENABLE([ltdl],
-              [AS_HELP_STRING(--disable-ltdl,disable ltdl support [[default=enabled]])],
-              [case "${enableval}" in
-                  no)
-                      ENABLE_LTDL=no
-                      ;;
-                  *)
-                      ENABLE_LTDL=yes
-                      ;;
-               esac],
-              [ENABLE_LTDL=yes])
-AC_MSG_RESULT(${ENABLE_LTDL})
-
-if test x"${ENABLE_LTDL}" = "xyes"; then
-    dnl we need this check for --enable-staticvm, otherwise ltdl can't find dlopen
-    if test x"${ENABLE_STATICVM}" = "xyes"; then
-        AC_CHECK_LIB(dl, dlopen,, [AC_MSG_ERROR(cannot find libdl)])
-    fi
-
-    AC_CHECK_HEADERS([ltdl.h],, [AC_MSG_ERROR(cannot find ltdl.h)])
-    AC_CHECK_LIB(ltdl, lt_dlopen,, [AC_MSG_ERROR(cannot find libltdl)])
-    AC_DEFINE([ENABLE_LTDL], 1, [use ltdl])
-fi
-
-AM_CONDITIONAL([ENABLE_LTDL], test x"${ENABLE_LTDL}" = "xyes")
-])
index 1f19362584b7ec0df5c8f1f8a09ec52562828e5c..c65a890f1cd5143dd9bd8a708e599429a474ddf4 100644 (file)
 
 #include <assert.h>
 
-#if defined(ENABLE_LIBJVM)
-# include <ltdl.h>
-#endif
-
 #if defined(ENABLE_JRE_LAYOUT)
 # include <errno.h>
 # include <libgen.h>
@@ -43,6 +39,7 @@
 #include "vm/types.h"
 
 #include "native/jni.h"
+#include "native/native.h"
 
 #if defined(ENABLE_JVMTI)
 # include "native/jvmti/jvmti.h"
 # include "threads/mutex.h"
 #endif
 
+#include "vmcore/system.h"
+
 #include "vm/vm.h"
 
 
+/* Defines. *******************************************************************/
+
+#define LIBJVM_NAME    NATIVE_LIBRARY_PREFIX"jvm"NATIVE_LIBRARY_SUFFIX
+
+
 /* forward declarations *******************************************************/
 
 static JavaVMInitArgs *cacao_options_prepare(int argc, char **argv);
@@ -67,15 +71,19 @@ static JavaVMInitArgs *cacao_options_prepare(int argc, char **argv);
 int main(int argc, char **argv)
 {
 #if defined(ENABLE_LIBJVM)
-       char           *path;
+       char*       path;
+
+# if defined(ENABLE_JRE_LAYOUT)
+       int         len;
+# endif
 #endif
 
 #if defined(ENABLE_LIBJVM)     
        /* Variables for JNI_CreateJavaVM dlopen call. */
-       lt_dlhandle     libjvm_handle;
-       lt_ptr          libjvm_vm_createjvm;
-       lt_ptr          libjvm_vm_run;
-       const char     *lterror;
+       void*       libjvm_handle;
+       void*       libjvm_vm_createjvm;
+       void*       libjvm_vm_run;
+       const charlterror;
 
        bool (*vm_createjvm)(JavaVM **, void **, void *);
        void (*vm_run)(JavaVM *, JavaVMInitArgs *);
@@ -105,40 +113,41 @@ int main(int argc, char **argv)
        /* get the path of the current executable */
 
        path = dirname(path);
+       len  = strlen(path) + strlen("/../lib/"LIBJVM_NAME) + strlen("0");
 
-       if ((strlen(path) + strlen("/../lib/libjvm") + strlen("0")) > 4096) {
+       if (len > 4096) {
                fprintf(stderr, "main: libjvm name to long for buffer\n");
                abort();
        }
 
        /* concatinate the library name */
 
-       strcat(path, "/../lib/libjvm");
+       strcat(path, "/../lib/"LIBJVM_NAME);
 # else
-       path = CACAO_LIBDIR"/libjvm";
+       path = CACAO_LIBDIR"/"LIBJVM_NAME;
 # endif
 
-       if (lt_dlinit()) {
-               fprintf(stderr, "main: lt_dlinit failed: %s\n", lt_dlerror());
-               abort();
-       }
-
        /* First try to open where dlopen searches, e.g. LD_LIBRARY_PATH.
           If not found, try the absolute path. */
 
-       if (!(libjvm_handle = lt_dlopenext("libjvm"))) {
+       libjvm_handle = system_dlopen(LIBJVM_NAME, RTLD_LAZY);
+
+       if (libjvm_handle == NULL) {
                /* save the error message */
 
-               lterror = strdup(lt_dlerror());
+               lterror = strdup(system_dlerror());
+
+               libjvm_handle = system_dlopen(path, RTLD_LAZY);
 
-               if (!(libjvm_handle = lt_dlopenext(path))) {
+               if (libjvm_handle == NULL) {
                        /* print the first error message too */
 
-                       fprintf(stderr, "main: lt_dlopenext failed: %s\n", lterror);
+                       fprintf(stderr, "main: system_dlopen failed: %s\n", lterror);
 
                        /* and now the current one */
 
-                       fprintf(stderr, "main: lt_dlopenext failed: %s\n", lt_dlerror());
+                       fprintf(stderr, "main: system_dlopen failed: %s\n",
+                                       system_dlerror());
                        abort();
                }
 
@@ -147,8 +156,10 @@ int main(int argc, char **argv)
                free((void *) lterror);
        }
 
-       if (!(libjvm_vm_createjvm = lt_dlsym(libjvm_handle, "vm_createjvm"))) {
-               fprintf(stderr, "main: lt_dlsym failed: %s\n", lt_dlerror());
+       libjvm_vm_createjvm = system_dlsym(libjvm_handle, "vm_createjvm");
+
+       if (libjvm_vm_createjvm == NULL) {
+               fprintf(stderr, "main: lt_dlsym failed: %s\n", system_dlerror());
                abort();
        }
 
@@ -166,8 +177,10 @@ int main(int argc, char **argv)
 #endif
 
 #if defined(ENABLE_LIBJVM)
-       if (!(libjvm_vm_run = lt_dlsym(libjvm_handle, "vm_run"))) {
-               fprintf(stderr, "lt_dlsym failed: %s\n", lt_dlerror());
+       libjvm_vm_run = system_dlsym(libjvm_handle, "vm_run");
+
+       if (libjvm_vm_run == NULL) {
+               fprintf(stderr, "main: system_dlsym failed: %s\n", system_dlerror());
                abort();
        }
 
index 9a4cd343f55d984a39cd2b519d419967c23e6e34..72c90371a5f3d4d99c04bd82426a2441b96fc2c9 100644 (file)
@@ -1,4 +1,4 @@
-/* src/native/native.c - table of native functions
+/* src/native/native.c - native library support
 
    Copyright (C) 1996-2005, 2006, 2007, 2008
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 #include <assert.h>
 #include <ctype.h>
 
-#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
-# include <ltdl.h>
-#endif
-
 #include <stdint.h>
 
 #include "vm/types.h"
@@ -52,6 +48,7 @@
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/global.h"
+#include "vm/resolve.h"
 #include "vm/stringlocal.h"
 #include "vm/vm.h"
 
@@ -60,7 +57,7 @@
 
 #include "vmcore/loader.h"
 #include "vmcore/options.h"
-#include "vm/resolve.h"
+#include "vmcore/system.h"
 
 #if defined(ENABLE_JVMTI)
 #include "native/jvmti/cacaodbg.h"
@@ -71,7 +68,7 @@
 
 static avl_tree_t *tree_native_methods;
 
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
 static hashtable *hashtable_library;
 #endif
 
@@ -91,12 +88,7 @@ bool native_init(void)
 {
        TRACESUBSYSTEMINITIALIZATION("native_init");
 
-#if defined(ENABLE_LTDL)
-       /* initialize libltdl */
-
-       if (lt_dlinit())
-               vm_abort("native_init: lt_dlinit failed: %s\n", lt_dlerror());
-
+#if defined(ENABLE_DL)
        /* initialize library hashtable, 10 entries should be enough */
 
        hashtable_library = NEW(hashtable);
@@ -507,7 +499,7 @@ functionptr native_method_resolve(methodinfo *m)
        utf                            *name;
        utf                            *newname;
        functionptr                     f;
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
        classloader_t                  *cl;
        hashtable_library_loader_entry *le;
        hashtable_library_name_entry   *ne;
@@ -542,7 +534,7 @@ functionptr native_method_resolve(methodinfo *m)
 
        f = NULL;
 
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
        /* Get the classloader. */
 
        cl = class_get_classloader(m->clazz);
@@ -561,10 +553,10 @@ functionptr native_method_resolve(methodinfo *m)
                ne = le->namelink;
                        
                while ((ne != NULL) && (f == NULL)) {
-                       f = (functionptr) (ptrint) lt_dlsym(ne->handle, name->text);
+                       f = (functionptr) (ptrint) system_dlsym(ne->handle, name->text);
 
                        if (f == NULL)
-                               f = (functionptr) (ptrint) lt_dlsym(ne->handle, newname->text);
+                               f = (functionptr) (ptrint) system_dlsym(ne->handle, newname->text);
 
                        ne = ne->hashlink;
                }
@@ -652,10 +644,10 @@ functionptr native_method_resolve(methodinfo *m)
 
 *******************************************************************************/
 
-#if defined(ENABLE_LTDL)
-lt_dlhandle native_library_open(utf *filename)
+#if defined(ENABLE_DL)
+void* native_library_open(utf *filename)
 {
-       lt_dlhandle handle;
+       void* handle;
 
        if (opt_verbosejni) {
                printf("[Loading native library ");
@@ -665,7 +657,7 @@ lt_dlhandle native_library_open(utf *filename)
 
        /* try to open the library */
 
-       handle = lt_dlopen(filename->text);
+       handle = system_dlopen(filename->text, RTLD_LAZY);
 
        if (handle == NULL) {
                if (opt_verbosejni)
@@ -673,8 +665,8 @@ lt_dlhandle native_library_open(utf *filename)
 
                if (opt_verbose) {
                        log_start();
-                       log_print("native_library_open: lt_dlopen failed: ");
-                       log_print(lt_dlerror());
+                       log_print("native_library_open: system_dlopen failed: ");
+                       log_print(dlerror());
                        log_finish();
                }
 
@@ -698,8 +690,8 @@ lt_dlhandle native_library_open(utf *filename)
 
 *******************************************************************************/
 
-#if defined(ENABLE_LTDL)
-void native_library_close(lt_dlhandle handle)
+#if defined(ENABLE_DL)
+void native_library_close(void* handle)
 {
        int result;
 
@@ -711,13 +703,13 @@ void native_library_close(lt_dlhandle handle)
 
        /* Close the library. */
 
-       result = lt_dlclose(handle);
+       result = system_dlclose(handle);
 
        if (result != 0) {
                if (opt_verbose) {
                        log_start();
-                       log_print("native_library_close: lt_dlclose failed: ");
-                       log_print(lt_dlerror());
+                       log_print("native_library_close: system_dlclose failed: ");
+                       log_print(dlerror());
                        log_finish();
                }
        }
@@ -731,8 +723,8 @@ void native_library_close(lt_dlhandle handle)
 
 *******************************************************************************/
 
-#if defined(ENABLE_LTDL)
-void native_library_add(utf *filename, classloader_t *loader, lt_dlhandle handle)
+#if defined(ENABLE_DL)
+void native_library_add(utf *filename, classloader_t *loader, void* handle)
 {
        hashtable_library_loader_entry *le;
        hashtable_library_name_entry   *ne; /* library name                       */
@@ -813,7 +805,7 @@ void native_library_add(utf *filename, classloader_t *loader, lt_dlhandle handle
 
 *******************************************************************************/
 
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
 hashtable_library_name_entry *native_library_find(utf *filename,
                                                                                                  classloader_t *loader)
 {
@@ -876,11 +868,11 @@ hashtable_library_name_entry *native_library_find(utf *filename,
 
 int native_library_load(JNIEnv *env, utf *name, classloader_t *cl)
 {
-#if defined(ENABLE_LTDL)
-       lt_dlhandle        handle;
+#if defined(ENABLE_DL)
+       void*   handle;
 # if defined(ENABLE_JNI)
-       lt_ptr             onload;
-       int32_t            version;
+       void*   onload;
+       int32_t version;
 # endif
 
        if (name == NULL) {
@@ -903,7 +895,7 @@ int native_library_load(JNIEnv *env, utf *name, classloader_t *cl)
 # if defined(ENABLE_JNI)
        /* Resolve JNI_OnLoad function. */
 
-       onload = lt_dlsym(handle, "JNI_OnLoad");
+       onload = system_dlsym(handle, "JNI_OnLoad");
 
        if (onload != NULL) {
                JNIEXPORT int32_t (JNICALL *JNI_OnLoad) (JavaVM *, void *);
@@ -919,7 +911,7 @@ int native_library_load(JNIEnv *env, utf *name, classloader_t *cl)
                   loaded. */
 
                if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
-                       lt_dlclose(handle);
+                       system_dlclose(handle);
                        return 0;
                }
        }
index 974a02bc0046a9ebe1be80985ccbd27ff8023174..89c8acb8c568d9599a48940df497cd5a02cd384e 100644 (file)
@@ -1,4 +1,4 @@
-/* src/native/native.h - table of native functions
+/* src/native/native.h - native library support
 
    Copyright (C) 1996-2005, 2006, 2007, 2008
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
 #include "config.h"
 
-#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
-# include <ltdl.h>
-#endif
-
 #include <stdint.h>
 
 #include "native/jni.h"
@@ -41,6 +37,7 @@
 #include "vmcore/class.h"
 #include "vmcore/loader.h"
 #include "vmcore/method.h"
+#include "vmcore/system.h"
 #include "vmcore/utf8.h"
 
 
 #define NATIVE_METHODS_COUNT    sizeof(methods) / sizeof(JNINativeMethod)
 
 
+#define NATIVE_LIBRARY_PREFIX     "lib"
+
+#if defined(__DARWIN__)
+# define NATIVE_LIBRARY_SUFFIX    ".dylib"
+#else
+# define NATIVE_LIBRARY_SUFFIX    ".so"
+#endif
+
+
 /* native_methods_node_t ******************************************************/
 
 typedef struct native_methods_node_t native_methods_node_t;
@@ -63,7 +69,7 @@ struct native_methods_node_t {
 
 /* hashtable_library_loader_entry *********************************************/
 
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
 typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
 typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
 
@@ -77,10 +83,10 @@ struct hashtable_library_loader_entry {
 
 /* hashtable_library_name_entry ***********************************************/
 
-#if defined(ENABLE_LTDL)
+#if defined(ENABLE_DL)
 struct hashtable_library_name_entry {
        utf                          *name;      /* library name                  */
-       lt_dlhandle                   handle;    /* libtool library handle        */
+       void*                         handle;    /* libtool library handle        */
        hashtable_library_name_entry *hashlink;  /* link for external chaining    */
 };
 #endif
@@ -93,10 +99,10 @@ bool native_init(void);
 void        native_method_register(utf *classname, const JNINativeMethod *methods, int32_t count);
 functionptr native_method_resolve(methodinfo *m);
 
-#if defined(ENABLE_LTDL)
-lt_dlhandle native_library_open(utf *filename);
-void        native_library_close(lt_dlhandle handle);
-void        native_library_add(utf *filename, classloader_t *loader, lt_dlhandle handle);
+#if defined(ENABLE_DL)
+void*       native_library_open(utf *filename);
+void        native_library_close(void* handle);
+void        native_library_add(utf *filename, classloader_t *loader, void *handle);
 hashtable_library_name_entry *native_library_find(utf *filename, classloader_t *loader);
 int         native_library_load(JNIEnv *env, utf *name, classloader_t *cl);
 #endif
index 25be0db79c490256d9d1a5bd524c8e4f47f5aa52..2ab5bd0dfd5219e6b9fca0d4edcbb8f3c91a8243 100644 (file)
@@ -279,17 +279,11 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIE
 
        /* calculate length of library name */
 
-       buffer_len = strlen("lib");
-
-       buffer_len += utf_bytes(u);
-
-#if defined(__DARWIN__)
-       buffer_len += strlen(".dylib");
-#else
-       buffer_len += strlen(".so");
-#endif
-
-       buffer_len += strlen("0");
+       buffer_len =
+               strlen(NATIVE_LIBRARY_PREFIX) +
+               utf_bytes(u) +
+               strlen(NATIVE_LIBRARY_SUFFIX) +
+               strlen("0");
 
        DMARKER;
 
@@ -297,14 +291,9 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIE
 
        /* generate library name */
 
-       strcpy(buffer, "lib");
+       strcpy(buffer, NATIVE_LIBRARY_PREFIX);
        utf_cat(buffer, u);
-
-#if defined(__DARWIN__)
-       strcat(buffer, ".dylib");
-#else
-       strcat(buffer, ".so");
-#endif
+       strcat(buffer, NATIVE_LIBRARY_SUFFIX);
 
        o = javastring_new_from_utf_string(buffer);
 
index 6d6e6838d359edbd15fd591d57185f298e5ad8ab..f927ab1b0067e054af5f5e15b1be43bd5bc44276 100644 (file)
 # include <dirent.h>
 #endif
 
+#if defined(HAVE_DLFCN_H)
+# include <dlfcn.h>
+#endif
+
 #if defined(HAVE_FCNTL_H)
 # include <fcntl.h>
 #endif
@@ -158,6 +162,42 @@ inline static char *system_dirname(char *path)
 }
 #endif
 
+inline static int system_dlclose(void* handle)
+{
+#if defined(HAVE_DLCLOSE)
+       return dlclose(handle);
+#else
+# error dlclose not available
+#endif
+}
+
+inline static char* system_dlerror(void)
+{
+#if defined(HAVE_DLERROR)
+       return dlerror();
+#else
+# error dlerror not available
+#endif
+}
+
+inline static void* system_dlopen(const char* filename, int flag)
+{
+#if defined(HAVE_DLOPEN)
+       return dlopen(filename, flag);
+#else
+# error dlopen not available
+#endif
+}
+
+inline static void* system_dlsym(void* handle, const char* symbol)
+{
+#if defined(HAVE_DLSYM)
+       return dlsym(handle, symbol);
+#else
+# error dlsym not available
+#endif
+}
+
 inline static FILE *system_fopen(const char *path, const char *mode)
 {
 #if defined(HAVE_FOPEN)