X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Sun, 25 Nov 2007 16:22:55 +0100 From: Peter Novak To: cygwin AT cygwin DOT com Subject: Ad: [app porting to cygwin] Invoking DLL exported routine problem - resolution(?) Message-ID: <20071125152255.GT5783@tu-clausthal.de> References: <20071125114321 DOT GS5783 AT aronde DOT net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OQpOxDqDax7rN7YB" Content-Disposition: inline In-Reply-To: <20071125114321.GS5783@aronde.net> X-PGP-Key: http://peter.aronde.net/publickey.asc X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Note-from-DJ: This may be spam --OQpOxDqDax7rN7YB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, this is a follow-up to my previous mail. It seems that after all I found a solution to my problem described in the previous e-mail. However, I do not fully understand what's going on as it seems to have something to do with the specification of C++ language and it seems to be a kind of g++ issue. Therefore, I would be glad if there's somebody who is able to enlighten me on the details of the issue together with why it works on Linux with gcc 4.1.3 and not on Cygwin with gcc 3.4.4. I would like to learn something from this. What I forgot to mention in my previous e-mail and what turned out to be crucial, is that my DLL uses std::cout for writing output to the console. I found, that whenever I have a print to cout in a routine, the subprocess crashes even *before* entering the routine(!). Struggling with gdb and multi-threaded application showed that the crash occurred in an esoteric place of: #0 0x6526f575 in std::ostream::sentry::sentry () at /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ostream.tcc:63 The code there lists a remark about supposedly an issue of GLIBC (???): 59 template 60 basic_ostream<_CharT, _Traits>& 61 basic_ostream<_CharT, _Traits>:: 62 operator<<(__ostream_type& (*__pf)(__ostream_type&)) 63 { 64 // _GLIBCXX_RESOLVE_LIB_DEFECTS 65 // DR 60. What is a formatted input function? 66 // The inserters for manipulators are *not* formatted output funct= ions. 67 return __pf(*this); 68 } Further research proved fruitful and I found an issue in the GCC bugzilla speaking about a similar problem: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D26123 According to Comment #9 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D26123#c9) the problem is with creation of the cout object and can be healed by a creation of a static instance of std::ios_base::Init in the routine. This indeed resolved my problem. Can somebody explain me why this worked the way it did? My guess is that it has something to do with Linux loading a shared library into the memory space of the running process, while on Win32 the DLL has it's own memory space (?)... Anyway, it does not explain why loading DLL from the main thread was OK, while loading it from a subprocess wasn't (all components, i.e. main process, subprocess and DLL use cout to print stuff to console). Thanks for any explanations. Best, Peter. --=20 peter.novak [at] tu-clausthal.de | http://cig.in.tu-clausthal.de/ Department of Informatics | Clausthal University of Technology Julius-Albert-Str. 4 | D-38678 Clausthal-Zellerfeld | Germany Tel +49 5323 72 71 90 | Fax +49 5323 72 71 39=20 --OQpOxDqDax7rN7YB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHSZNPwqpFHLvXwlwRAkExAJ9f+/T647eCbryHJwJ5FLXQ/UJdfgCfQRhn nslCzaCbj2GRO72iWrbTNHs= =GTxP -----END PGP SIGNATURE----- --OQpOxDqDax7rN7YB--