diff --git a/README b/README index 0591d55..eede54d 100644 --- a/README +++ b/README @@ -272,6 +272,12 @@ Rename Pre-build.2 to pthreads. Open the provided workspace build\libupnp.dsw with Visual C++ 6.0 and select Build->Build libupnp.dll (F7) +For building a static library instead of a DLL and for using the static +pthreads-w32 library following switches need to be defined additionally: + +UPNP_STATIC_LIB - for creating a statically linkable UPnP-library +PTW32_STATIC_LIB - for using the static pthreads32 library + 5) Install/Uninstall Instructions ------------------------------------------- diff --git a/ixml/inc/ixml.h b/ixml/inc/ixml.h index 0301357..b0a6b81 100644 --- a/ixml/inc/ixml.h +++ b/ixml/inc/ixml.h @@ -38,11 +38,15 @@ #include #ifdef WIN32 - #ifdef LIBUPNP_EXPORTS - // set up declspec for dll export to make functions visible to library users - #define EXPORT_SPEC __declspec(dllexport) + #ifndef UPNP_STATIC_LIB + #ifdef LIBUPNP_EXPORTS + // set up declspec for dll export to make functions visible to library users + #define EXPORT_SPEC __declspec(dllexport) + #else + #define EXPORT_SPEC __declspec(dllimport) + #endif #else - #define EXPORT_SPEC __declspec(dllimport) + #define EXPORT_SPEC #endif #else #define EXPORT_SPEC diff --git a/threadutil/inc/ithread.h b/threadutil/inc/ithread.h index b5ea840..49dfb43 100644 --- a/threadutil/inc/ithread.h +++ b/threadutil/inc/ithread.h @@ -527,11 +527,15 @@ extern "C" { #define imillisleep(x) usleep(1000*x) #ifdef WIN32 - #ifdef LIBUPNP_EXPORTS - // set up declspec for dll export to make functions visible to library users - #define EXPORT_SPEC __declspec(dllexport) + #ifndef UPNP_STATIC_LIB + #ifdef LIBUPNP_EXPORTS + // set up declspec for dll export to make functions visible to library users + #define EXPORT_SPEC __declspec(dllexport) + #else + #define EXPORT_SPEC __declspec(dllimport) + #endif #else - #define EXPORT_SPEC __declspec(dllimport) + #define EXPORT_SPEC #endif #else #define EXPORT_SPEC diff --git a/threadutil/src/ThreadPool.c b/threadutil/src/ThreadPool.c index 4429e3f..e017464 100644 --- a/threadutil/src/ThreadPool.c +++ b/threadutil/src/ThreadPool.c @@ -382,6 +382,12 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default: int retCode = 0; int persistent = -1; ThreadPool *tp = ( ThreadPool * ) arg; + //leuk_he allow static linking + #ifdef WIN32 + #ifdef PTW32_STATIC_LIB + pthread_win32_thread_attach_np(); + #endif + #endif assert( tp != NULL ); @@ -449,7 +455,12 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default: tp->totalThreads--; ithread_cond_broadcast( &tp->start_and_shutdown ); ithread_mutex_unlock( &tp->mutex ); - + //leuk_he + #ifdef WIN32 + #ifdef PTW32_STATIC_LIB + pthread_win32_thread_detach_np (); + #endif + #endif return NULL; } @@ -478,6 +489,12 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default: ithread_cond_broadcast( &tp->start_and_shutdown ); ithread_mutex_unlock( &tp->mutex ); + //leuk_he + #ifdef WIN32 + #ifdef PTW32_STATIC_LIB + pthread_win32_thread_detach_np (); + #endif + #endif return NULL; } else { @@ -705,6 +722,12 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default: if( tp == NULL ) { return EINVAL; } + //leuk_he + #ifdef WIN32 + #ifdef PTW32_STATIC_LIB + pthread_win32_process_attach_np(); + #endif + #endif retCode += ithread_mutex_init( &tp->mutex, NULL ); assert( retCode == 0 ); diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index 9e68bb2..933d656 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -47,11 +47,15 @@ #endif #ifdef WIN32 - #ifdef LIBUPNP_EXPORTS - // set up declspec for dll export to make functions visible to library users - #define EXPORT_SPEC __declspec(dllexport) + #ifndef UPNP_STATIC_LIB + #ifdef LIBUPNP_EXPORTS + // set up declspec for dll export to make functions visible to library users + #define EXPORT_SPEC __declspec(dllexport) + #else + #define EXPORT_SPEC __declspec(dllimport) + #endif #else - #define EXPORT_SPEC __declspec(dllimport) + #define EXPORT_SPEC #endif #else #define EXPORT_SPEC diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c index f7348cb..ee386af 100644 --- a/upnp/src/api/upnpapi.c +++ b/upnp/src/api/upnpapi.c @@ -415,6 +415,13 @@ UpnpFinish( ) // remove all virtual dirs UpnpRemoveAllVirtualDirs( ); + //leuk_he allow static linking: + #ifdef WIN32 + #ifdef PTW32_STATIC_LIB + pthread_win32_thread_detach_np (); + #endif + #endif + UpnpSdkInit = 0;