From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31473 invoked by alias); 30 Mar 2005 23:49:01 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 31378 invoked from network); 30 Mar 2005 23:48:41 -0000 Received: from unknown (HELO quokka.dot.net.au) (202.147.68.16) by sourceware.org with SMTP; 30 Mar 2005 23:48:41 -0000 Received: from [202.147.81.148] (helo=ip-81-148.dot.net.au) by quokka.dot.net.au with esmtp (Exim 3.35 #1 (Debian)) id 1DGmvQ-0001x6-00 for ; Thu, 31 Mar 2005 09:48:40 +1000 Subject: Re: Static link (MSVC), alteration proposal From: Ross Johnson To: Pthreads-Win32 list In-Reply-To: <1112192108.9a7b65f2515a2@mail.bg> References: <1112192108.9a7b65f2515a2@mail.bg> Content-Type: text/plain; charset=UTF-8 Date: Wed, 30 Mar 2005 23:49:00 -0000 Message-Id: <1112226518.19990.69.camel@desk.home> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2005/txt/msg00051.txt.bz2 Hi, Thanks for the changes and the explanations. They certainly fill a gap. On Wed, 2005-03-30 at 17:15 +0300, Dimitar Panayotov wrote: > Hello. > I show (as short as I can) a small note about statically > linking to the Pthreads-Win32 library. >=20 > My deprecation: why using _DLL macro to determine whether > to link statically or dynamically? The PTW32_BUILD conditional was added by me. I've never built the library statically, and don't test this side of things. This is because the library is essentially designed for dynamic linking (although it can be static linked provided your app/dll does some extra things - see later). The _DLL conditional may have been contributed by someone who has statically linked the library, and it presumably worked for them. I don't recall adding it myself, but that's also possible - in which case I would have been blind to the implications you've described. > 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 > Pthreads-Win32? This isn't deliberate, it just hasn't been an issue before. > In order to link my dll with Pthreads-Win32 statically, I > had to do some minor changes: >=20 Please see the description of:- pthread_win32_process_attach_np () pthread_win32_process_detach_np () pthread_win32_thread_attach_np () pthread_win32_thread_detach_np () in README.NONPORABLE. You need to call these explicitly when static linking. Since your project is a dll, I assume you can just call them from your own dllMain(). > 1. Code in which I altered: >=20 > #ifdef _DLL > # ifdef PTW32_BUILD > # define PTW32_DLLPORT __declspec (dllexport) > # else > # define PTW32_DLLPORT __declspec (dllimport) > # endif > #endif >=20 > with: >=20 > #ifdef PTW32_DLL > # ifdef PTW32_BUILD > # define PTW32_DLLPORT __declspec (dllexport) > # else > # define PTW32_DLLPORT __declspec (dllimport) > # endif > #else > #define PTW32_DLLPORT > #endif >=20 > 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. :) >=20 > 2. In and preprocessor code was > similar, with the difference that there were no #ifdef > _DLL. There I changed the code exactly as in >=20 > 3. In I altered the following code: >=20 > #include >=20 > with: >=20 > #ifdef PTW32_DLL > #include > #endif >=20 > --- >=20 > 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(). >=20 > Sorry for the bad English, it's not my native language. >=20 > 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. >=20 > --------------------- > | Dimitar Panayotov | > | develop@mail.bg | > | +359886420488 | > --------------------- >=20 > ----------------------------- >=20 > "=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8=D0=BD" - =D0=94= =D0=B6=D0=BE=D0=BD =D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8= =D0=BD (=D0=9A=D0=B8=D0=B0=D0=BD=D1=83 =D0=A0=D0=B8=D0=B9=D0=B2=D1=81) =D0= =B2=D0=B5=D1=87=D0=B5 =D0=B5 =D0=B1=D0=B8=D0=BB =D0=B2 =D0=B0=D0=B4=D0=B0. > =D0=A2=D0=BE=D0=B9 =D0=B8=D0=BC=D0=B0 =D0=B4=D0=B0=D1=80=D0=B1=D0=B0=D1= =82=D0=B0 =D0=B4=D0=B0 =D1=80=D0=B0=D0=B7=D0=BF=D0=BE=D0=B7=D0=BD=D0=B0=D0= =B2=D0=B0 =D0=B4=D0=B5=D0=BC=D0=BE=D0=BD=D0=B8=D1=82=D0=B5, =D0=BF=D1=80=D0= =B8=D0=B5=D0=BB=D0=B8 =D1=87=D0=BE=D0=B2=D0=B5=D1=88=D0=BA=D0=B8 =D0=BE=D0= =B1=D0=BB=D0=B8=D0=BA. > http://www.mail.bg/info/?action=3D1200&title=3D%CA%EE%ED%F1%F2%E0%ED%F2%E= 8%ED%20%282005%29&date >=20