Commit 83432ba2df9a5f526d94370815e48b21a5beb424

Dennis Nienhüser 2015-03-11T20:00:11

Add import/export symbols for MSVC. This results in an import .lib file. Closes #4. Some fixes by Timothy Gu <timothygu99@gmail.com> Signed-off-by: Timothy Gu <timothygu99@gmail.com>

diff --git a/dlfcn.c b/dlfcn.c
index 46c85ce..75f5c81 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -20,6 +20,7 @@
 #include <windows.h>
 #include <stdio.h>
 
+#define DLFCN_WIN32_EXPORTS
 #include "dlfcn.h"
 
 /* Note:
diff --git a/dlfcn.h b/dlfcn.h
index 413c0ab..06c3529 100644
--- a/dlfcn.h
+++ b/dlfcn.h
@@ -24,6 +24,12 @@
 extern "C" {
 #endif
 
+#if defined(DLFCN_WIN32_EXPORTS)
+#   define DLFCN_EXPORT __declspec(dllexport)
+#elif defined (_MSC_VER) // FIXME: MinGW support
+#   define DLFCN_EXPORT __declspec(dllimport)
+#endif
+
 /* POSIX says these are implementation-defined.
  * To simplify use with Windows API, we treat them the same way.
  */
@@ -41,10 +47,10 @@ extern "C" {
 #define RTLD_DEFAULT    0
 #define RTLD_NEXT       0
 
-void *dlopen ( const char *file, int mode );
-int   dlclose( void *handle );
-void *dlsym  ( void *handle, const char *name );
-char *dlerror( void );
+DLFCN_EXPORT void *dlopen ( const char *file, int mode );
+DLFCN_EXPORT int   dlclose(void *handle);
+DLFCN_EXPORT void *dlsym(void *handle, const char *name);
+DLFCN_EXPORT char *dlerror(void);
 
 #ifdef __cplusplus
 }