From a630d84413ce7997eca1caa637a220932b67d545 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Thu, 4 Mar 2010 12:35:18 +0900 Subject: [PATCH] adding dll fixes for mingw --- Makefile | 6 +++++- eval.c | 18 +++++++++++++++++- include/chibi/sexp.h | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fcc10ae6..37aa5ca1 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ GENSTATIC ?= ./tools/genstatic.scm # system configuration - if not using GNU make, set PLATFORM and the # following flags as necessary. +# +LIBDL = -ldl + ifndef PLATFORM ifeq ($(shell uname),Darwin) PLATFORM=macosx @@ -52,6 +55,7 @@ CLIBFLAGS = -shared CPPFLAGS += -DSEXP_USE_STRING_STREAMS=0 -DBUILDING_DLL -DSEXP_USE_DEBUG=0 LDFLAGS += -Wl,--out-implib,libchibi-scheme$(SO).a STATICFLAGS = -DSEXP_USE_DL=0 +LIBDL = else SO = .so EXE = @@ -76,7 +80,7 @@ ifeq ($(SEXP_USE_DL),0) XLDFLAGS := $(LDFLAGS) $(GCLDFLAGS) -lm XCFLAGS := -Wall -DSEXP_USE_DL=0 -g3 $(CFLAGS) else -XLDFLAGS := $(LDFLAGS) $(GCLDFLAGS) -ldl -lm +XLDFLAGS := $(LDFLAGS) $(GCLDFLAGS) $(LIBDL) -lm XCFLAGS := -Wall -g3 $(CFLAGS) endif diff --git a/eval.c b/eval.c index d2360568..8e18b8f7 100644 --- a/eval.c +++ b/eval.c @@ -2039,7 +2039,22 @@ void sexp_warn_undefs (sexp ctx, sexp from, sexp to, sexp out) { } #if SEXP_USE_DL -sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { +#ifdef __MINGW32__ +#include +static sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { + sexp_proc2 init; + HINSTANCE handle = LoadLibraryA(sexp_string_data(file)); + if(!handle) + return sexp_compile_error(ctx, "couldn't load dynamic library", file); + init = (sexp_proc2) GetProcAddress(handle, "sexp_init_library"); + if(!init) { + FreeLibrary(handle); + return sexp_compile_error(ctx, "dynamic library has no sexp_init_library", file); + } + return init(ctx, env); +} +#else +static sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { sexp_proc2 init; void *handle = dlopen(sexp_string_data(file), RTLD_LAZY); if (! handle) @@ -2052,6 +2067,7 @@ sexp sexp_load_dl (sexp ctx, sexp file, sexp env) { return init(ctx, env); } #endif +#endif sexp sexp_load (sexp ctx, sexp source, sexp env) { #if SEXP_USE_DL diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 054be66c..35dc565a 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -18,8 +18,10 @@ extern "C" { #include #if SEXP_USE_DL +#ifndef __MINGW32__ #include #endif +#endif #ifdef PLAN9 #include