From 89ed8b193485c94b65eb8ba1014f6832d23707e1 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 20 May 2010 17:04:48 +0200 Subject: loader works on windows --- tests/library/Makefile.W32 | 11 ++++++++++- tests/library/test_loader.c | 19 +++++++++++++++++-- tests/library/testlib.c | 8 +++++++- 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/library/Makefile.W32 b/tests/library/Makefile.W32 index 4ebcab9..7c44d8d 100644 --- a/tests/library/Makefile.W32 +++ b/tests/library/Makefile.W32 @@ -13,11 +13,20 @@ INCLUDE_LIBS = \ TEST_BINS = \ test_loader.exe +TEST_OBJS = \ + testlib.obj + +TEST_LIBRARIES = \ + testlib.dll + !INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk +testlib.dll: $(TEST_OBJS) + $(LINK) /DLL /nologo /out:$@ $(LDFLAGS) $(LIBS) $? + test_loader.exe: test_loader.obj $(TOPDIR)\src\wolf.lib -local_all: +local_all: $(TEST_LIBRARIES) local_clean: diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c index 0eef9f2..6fd5d2e 100644 --- a/tests/library/test_loader.c +++ b/tests/library/test_loader.c @@ -21,6 +21,12 @@ #include /* for fprintf */ #include /* for assert */ +#ifdef _WIN32 +#define LIBRARY_NAME "testlib.dll" +#else +#define LIBRARY_NAME "./testlib.so.0.0.0" +#endif + int main( void ) { wolf_library_p library; wolf_error_t error; @@ -32,7 +38,7 @@ int main( void ) { int res = 0; /* open the libray */ - library = wolf_library_load( "./testlib.so.0.0.0", &error ); + library = wolf_library_load( LIBRARY_NAME, &error ); if( error != WOLF_OK ) { fprintf( stderr, "Error %d loading the library: %s\n", error, wolf_library_errmsg( error, library, errbuf, 512 ) ); @@ -44,9 +50,18 @@ int main( void ) { * http://en.wikipedia.org/wiki/Dynamic_loading */ symbol = wolf_library_get_func( library, "multiply_by_two", &error ); + if( error != WOLF_OK ) { + fprintf( stderr, "Error %d fetching a function from the library: %s\n", + error, wolf_library_errmsg( error, library, errbuf, 512 ) ); + return EXIT_FAILURE; + } +#if !defined _WIN32 alias.obj = symbol; func = alias.func; - +#else + func = (multiply_by_two_func)symbol; +#endif + /* call it */ res = func( 7 ); assert( res == 14 ); diff --git a/tests/library/testlib.c b/tests/library/testlib.c index f8e457a..b240819 100644 --- a/tests/library/testlib.c +++ b/tests/library/testlib.c @@ -1,4 +1,10 @@ -int multiply_by_two( int a ); +#ifdef _WIN32 +#define DLLEXPORT __declspec( dllexport ) +#else +#define DLLEXPORT +#endif + +DLLEXPORT int multiply_by_two( int a ); int multiply_by_two( int a ) { return a * 2; -- cgit v1.2.3-54-g00ecf