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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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
}