DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 54MJKsYJ390079 Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 54MJKsYJ390079 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=PLBsFDmg X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 510FD385772F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1747941653; bh=RyRsE8v8f+10lC/ILCVDMuwxPQjHpspF/Rh673PvFag=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=PLBsFDmgZNGMpfDCC3rBLxKHpwxv30RniKxPktlqb0ceybX58/5sU4+uakWs9APac +5zsQ8AzkbwvktGXPVom+th5rJqXgSpQyqlbmk442R3zjr6iz8Koh98102NVhOhD83 4TI1mqr5r8LAMjLpmQ4WJ1q6JyAmVYfJDNEAa08c= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83FAA3857B9E ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 83FAA3857B9E ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747941589; cv=none; b=svszZ7EqqVSXTntot9k7yLhSBvmfbSbHFAN9irn1QRE4b18FdGxRHEkjANq3lX43NqLhSNKyVSijbwZMlcSyE+sL1RRXO/KR6kTG4RiBHivU7IpK08E8JLSXJrFvOaGSmDv4piUBEcMGM12qgS8n0rYH0gih9o1Y8lcG0PTFW44= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747941589; c=relaxed/simple; bh=LszgQ3Na6nZq+2cCE0uE8eOM4PzDvLQWSZ1OXkdI9Z4=; h=Message-ID:Date:MIME-Version:From:Subject:To:DKIM-Signature; b=Urix/1wsxveyRwNr8whRRLKKtJg3EJpw9fhjd8v/DDPZzk252gfbyl1VGldlEhYtK1ZAzWDUirs02S0wP65brZWlcgUpMxMPkSP2kBHe/bP5Pw08bd5I9tLhNL+kFDRgHVvKpGPBtwOHyqLmXaiy6E/PrsOfRdRH3F371s5xHWk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83FAA3857B9E Message-ID: <24d8214c-476a-4d6b-8fc0-be2c4320d52c@SystematicSW.ab.ca> Date: Thu, 22 May 2025 13:19:46 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: gcc links to libcmain when generating a dll Content-Language: en-CA To: cygwin AT cygwin DOT com References: <5b9f8d4b-0a5a-4aea-99cb-f2c24a6a127a AT slipbits DOT com> Organization: Systematic Software In-Reply-To: <5b9f8d4b-0a5a-4aea-99cb-f2c24a6a127a@slipbits.com> X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: 9ED372000E X-Stat-Signature: dgr6ud7g7djaptgidwp9c7c9z785faym X-Session-Marker: 427269616E2E496E676C69734053797374656D6174696353572E61622E6361 X-Session-ID: U2FsdGVkX18I4x61s1ThZp5YORgKVeAkDKdAckpfJ94= X-HE-Tag: 1747941587-269950 X-HE-Meta: U2FsdGVkX18Y4dqZeUWSP9aKsJCPJUHnFVpMwm9BH3fJmH4TlyKblCUsWIBFrI+spvvtg4JrNm1VZuj4yFZPdg8w9pEw0l+kWZ9zbdju7upp2VY9ubR/kHKfhuDwB99ABeuz8dHI7Yj+r5aLzuEw/JBEDQPf81VJm3O3Htqo9VE96mWCcVlw/S+XvGMIz4yCF4Fus2NKfgl+iHcewyCn+ZtK4Dtfw+kBba7/Wwj+SfHcC3peLntAXr7xx7rf9cLCaM2nVud1zyhzepsPQeNz2cbKZq8e5+fcVHbUfFkKZUAGlOPtJ2aumEVemM6hCOiCkfKLK/4skhTM3xYkCAvh1aM0+5H9ZgYL X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Brian Inglis via Cygwin Reply-To: cygwin AT cygwin DOT com Cc: Brian Inglis Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 54MJKsYJ390079 On 2025-05-22 12:37, Arthur Schwarz via Cygwin wrote: > I can't figure this one out. > > > clear;g++ -flinker-output=dyn -o slip.dll *.o > > generates: > > /usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/ > gcc/x86_64-pc-cygwin/12/../../../../lib/libcygwin.a(libcmain.o): in function > `main': > /usr/src/debug/cygwin-3.6.1-1/winsup/cygwin/lib/libcmain.c:37: > (.text.startup+0x79): undefined reference to `WinMain' > collect2: error: ld returned 1 exit status > > But I am developing a dll, not a windows application. The gcc.pdf manual says: > >    -flinker-output=type >    This option controls code generation of the link-time optimizer. By >    default the >    linker output is automatically determined by the linker plugin. For >    debugging >    the compiler and if incremental linking with a non-LTO object file >    is desired, >    it may be useful to control the type manually. > >    If type is ‘dyn’, code generation produces a shared library. In this >    case ‘-fpic’ >    or ‘-fPIC’ is preserved, but not enabled automatically. This allows >    to build >    shared libraries without position-independent code on architectures >    where this >    is possible, i.e. on x86. > > My code is not executable and nowhere links to or uses any Windows code. It does > not have a WinMain method and there is no link to libcmain.o in the object > folder (*.o does not have libcmain.o). > > How do I get rid of this link error? Tell the linker (ld/gcc/g++) not the LTO code generator! If your "code" is not executable (data?) then LTO is irrelevant. Please note: $ info gcc flinker-output | tail -8 ---------- Footnotes ---------- (1) On some systems, ‘gcc -shared’ needs to build supplementary stub code for constructors to work. On multi-libbed systems, ‘gcc -shared’ must select the correct support libraries to link against. *Failing to supply the correct flags may lead to subtle defects.* Supplying them in cases where they are not necessary is innocuous. A couple of examples from cygport scripts: $ grep -iA3 'CC.*-shared' **/*.cygport expect.cygport: cygmake SHLIB_LD='$(CC) -shared -Wl,--out-implib,$@.a' -- libvpx.cygport: $CC -shared -fpic -o cygvpx-$ABI.dll \ libvpx.cygport- -Wl,--out-implib,libvpx.dll.a \ libvpx.cygport- -Wl,--whole-archive,libvpx.a,--no-whole-archive \ libvpx.cygport- -Wl,--version-script,$EXPORT_FILE Your program will need to link with the implib. -- Take care. Thanks, Brian Inglis Calgary, Alberta, Canada La perfection est atteinte Perfection is achieved non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add mais lorsqu'il n'y a plus rien à retrancher but when there is no more to cut -- Antoine de Saint-Exupéry -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple