public inbox for
 help / color / mirror / Atom feed
* Static link (MSVC), alteration proposal
@ 2005-03-30 14:15 Dimitar Panayotov
  2005-03-30 23:49 ` Ross Johnson
  0 siblings, 1 reply; 4+ messages in thread
From: Dimitar Panayotov @ 2005-03-30 14:15 UTC (permalink / raw)
  To: pthreads-win32

 I show (as short as I can) a small note about statically
linking to the Pthreads-Win32 library.

 My deprecation: why using _DLL macro to determine whether
to link statically or dynamically? As you know, _DLL is
used by the Microsoft headers; when defined, it links your
app/lib/dll with an import library, which by itself points
to the dynamically linked libraries, containing
implementation of the C-Runtime Library on Win32. When _DLL
not defined, C-Runtime is linked statically into your
app/lib/dll. So, why the type of the linkage with the
C-Runtime is bound to the type of linkage with

 In order to link my dll with Pthreads-Win32 statically, I
had to do some minor changes:

1. Code in <pthread.h> which I altered:

#ifdef _DLL
# ifdef PTW32_BUILD
#  define PTW32_DLLPORT __declspec (dllexport)
# else
#  define PTW32_DLLPORT __declspec (dllimport)
# endif


#ifdef PTW32_DLL
#  ifdef PTW32_BUILD
#    define PTW32_DLLPORT __declspec (dllexport)
#  else
#    define PTW32_DLLPORT __declspec (dllimport)
#  endif
#define PTW32_DLLPORT

You surely realize what I do: First, I use a separate macro
to determine whether to link statically or dynamically to
Pthreads-Win32. Second, if you not explicitly define
PTW32_DLLPORT as an empty macro, MSVC compiler expands it
to __declspec(dllimport), no matter of the fact, that the
preprocessor does not actually enter in the #ifdef
PTW32_DLL block!! It's so funny. Of course, I did not
wasted my time to check some strange implications which
could be made by the MSVC compiler, since it always knows
better than you what you actually want. :)

2. In <semaphore.h> and <sched.h> preprocessor code was
similar, with the difference that there were no #ifdef
_DLL. There I changed the code exactly as in <pthread.h>

3. In <pthread.c> I altered the following code:

#include <dll.c>


#ifdef PTW32_DLL
#include <dll.c>


 The result of all this is: when you do not define PTW32_DLL
in your build, you will be sure that Pthread-Win32
function's declarations will not contain
__declspec(dllexport) / __declspec(dllimport). Also, when
you build your own DLL, you assure that no conflict will
occur with the Pthread-Win32's DllMain().

 Sorry for the bad English, it's not my native language.

 Of course, one human does not need to be a genius to note
such things, nor will I pretend to be very smart for
writing this note. :) I just hope it to be useful.

| Dimitar Panayotov |
|   |
| +359886420488     |


"Константин"  -  Джон Константин (Киану Рийвс) вече е бил в ада.
Той има дарбата да разпознава демоните, приели човешки облик.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-31  8:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-30 14:15 Static link (MSVC), alteration proposal Dimitar Panayotov
2005-03-30 23:49 ` Ross Johnson
2005-03-31  7:42   ` Dimitar Panayotov
2005-03-31  8:29     ` Ross Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).