delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/10/17/18:54:46

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Thorsten Kampe <thorsten AT thorstenkampe DOT de>
Subject: Re: Using a Cygwin-built DLL outside of Cygwin
Date: Wed, 17 Oct 2007 23:53:57 +0100
Lines: 71
Message-ID: <ff63q5$vop$1@ger.gmane.org>
References: <1192647409 DOT 21421 DOT 528 DOT camel AT strangepork>
Mime-Version: 1.0
User-Agent: MicroPlanet-Gravity/2.70.2067
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

* Christian Kreibich (Wed, 17 Oct 2007 11:56:49 -0700)
> I have a library originally developed on Linux/FreeBSD that is building
> fine on Cygwin. It also works fine if I build executables using this
> library inside Cygwin. The goal however is for the resulting DLL to work
> outside of Cygwin, for example with Visual Studio. I am running into a
> few problems trying to achieve this. I'll first describe what I've
> tried, and ask questions below.
> 
> Following http://www.cygwin.com/ml/cygwin/2004-03/msg00453.html , I use
> this command to link the library:
> 
> gcc -shared  ${objects} \
> 	-Wl,--output-def=.libs/cygfoo.def \
> 	-Wl,--export-all-symbols \
> 	-Wl,--enable-auto-import \
> 	-Wl,--enable-auto-image-base \
> 	-Wl,--add-stdcall-alias \
> 	-Wl,--enable-stdcall-fixup \
> 	-Wl,--enable-auto-image-base \
> 	-o .libs/cygfoo-0.dll \
> 	-lssl -lcrypto
> 
> (The library uses OpenSSL, which I have included in my Cygwin setup.)
> 
> I threw out --compat-implib since it no longer seems to exist (per "man
> ld"). I originally also used --out-implib to generate an import library,
> but like http://www.cygwin.com/ml/cygwin/2000-10/msg01051.html I'd get a
> 'multiple ".text" sections found with different attributes' warning when
> using the resulting implib. (I have also tried the command shown at
> http://cygwin.com/cygwin-ug-net/dll.html , with the same result.)
> 
> I now instead use MSVC's lib command, which seems to fix that problem:
> 
>   LIB /machine:ix86 /def:cygfoo.def /out:cygfoo.lib
> 
> Given the resulting .dll, .lib, and .def, I can compile a dummy
> application in MSVC. However, this executable has two problems. First,
> output to stdout/stderr does not appear. A number of people seem to have
> noticed this. One related posting recommended the use file I/O instead,
> but if I attempt this (or indeed any cross-DLL-boundary calls), the
> application crashes. Simpler function calls whose execution paths don't
> leave my DLL work fine.
> 
> My questions:
> 
> - Is there a Cygwin-only way to avoid the MSVC lib command detour, to
> avoid the "multiple .text sections" issue?
> 
> - I have gleaned from related postings and FAQ 6.12 that the crashes are
> due to the use of cygwin1.dll and msvcrt.dll (and/or related Windows
> DLLs) in the same executable. Is this correct?
> 
> - If so, is there a way to avoid the problem while still building the
> library in my cozy Cygwin/POSIX environment? My understanding is that
> -mno-cygwin doesn't help in that regard (per FAQ 6.10), and that I have
> to keep cygwin1.dll (per FAQ 6.11).
> 
> - If getting rid of msvcrt.dll is the answer, what are the implications
> for building Windows-native applications? (And, assuming this is
> possible, if a kind soul could tell me how I'd go about doing this even
> though it's not a question at the heart of this list, that'd be much
> appreciated...)

Aren't these FAQs?

* Can I link with both MSVCRT*.DLL and cygwin1.dll?
http://cygwin.com/faq/faq.programming.html#faq.programming.msvcrt-and-
cygwin

* How do I use cygwin1.dll with Visual Studio or MinGW?
http://cygwin.com/faq/faq.programming.html#faq.programming.msvs-mingw


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019