public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Charles Wilson <cygwin@cwilson.fastmail.fm>
To: cygwin@cygwin.com
Subject: Re: -static not working with gcc 4.3.4
Date: Thu, 03 Feb 2011 19:50:00 -0000	[thread overview]
Message-ID: <4D4B0702.9090600@cwilson.fastmail.fm> (raw)
In-Reply-To: <30838541.post@talk.nabble.com>

On 2/3/2011 2:34 PM, gvidaver wrote:
> It still requires the cygwin1.dll:
> 
> $ g++ -v
> ...
> gcc version 4.5.0 (GCC)
> 
> $ g++ test.c -o test -static
> 
> $ ldd test.exe
>         ...
>         cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000)
>         ...

Uhm, yes.  The cygwin-provided gcc is a cygwin compiler, intended for
generating cygwin DLLs and executables.  Thus, all dlls and exes it
generates will require the cygwin1.dll (since there is not now, and will
not be, any "static version" of cygwin1.dll).

Older cygwin gcc's had a controversial mode "-mno-cygwin" that,
basically, turned the cygwin gcc into a buggy version of the mingw gcc.
 It often had "cygwin pollution" problems, and many people misunderstood
the purpose of the flag.  So, it has been deprecated for about five
years now, and was finally removed with the release of cygwin's gcc-4.3.4.

> And apparently the only alternative is mingw, see:
> 
> http://cygwin.com/faq/faq-nochunks.html#faq.programming.static-linking
> "it is not possible to statically link with a Cygwin library to obtain an
> independent, self-contained executable. "
> 
> $ i686-w64-mingw32-g++ -v
> ...
> gcc version 4.5.1 (GCC)
> 
> $ i686-w64-mingw32-g++ test.c -o test -static
> 
> $ ldd test.exe
>         ntdll.dll => ... path to Windows dlls
>         kernel32.dll => ... 
>         KERNELBASE.dll => ...
>         msvcrt.dll => ...
> 
> (I.e. no dependencies on anything besides system dlls.)

Right, but on the "cygwin system", the cygwin1.dll IS a system dll (as
are cyggcc_s-1.dll, cygstdc++-6.dll, and the other "language" runtime
libraries). All -static does is force the compiler to attempt to link
statically to OTHER user libs that you'd pass on the link command, like
-lintl -lz -ljpeg etc.

You can, in SOME cases, avoid a shared dependency on the *language*
runtimes (for C and C++ alone) by using the -static-libgcc and/or
-static-libstdc++, but...there are complexities with that.

However, using the cygwin compiler, you cannot (*) avoid a dependency on
the cygwin runtime cygwin1.dll.  This is not a bug; it is part of the
design.

Now, the OP in this thread posted a problem with -static related to the
language runtime library for C (gcc_s aka cyggcc_s-1.dll) but that's a
whole different issue that your attempt to avoid cygwin1.dll.


(*) OK, sure, you can use -nostdlib but...I guarantee you won't like the
results.  It just won't work, and you'd be better off simply using the
mingw compiler instead (or one of cygwin's mingw-target cross compilers).

--
Chuck

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

      parent reply	other threads:[~2011-02-03 19:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-17  7:02 Samuel Thibault
2010-10-17  8:15 ` R: " Marco Atzeri
2010-10-17 22:46   ` Samuel Thibault
2010-10-18 12:58 ` Nellis, Kenneth
2010-10-18 13:12   ` Samuel Thibault
2010-10-18 13:53     ` Marco Atzeri
2010-10-19  7:46       ` Samuel Thibault
2011-02-03 19:34         ` gvidaver
2011-02-03 19:48           ` marco atzeri
2011-02-03 21:21             ` gvidaver
2011-02-03 22:19               ` Christopher Faylor
2011-02-03 19:50           ` Charles Wilson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D4B0702.9090600@cwilson.fastmail.fm \
    --to=cygwin@cwilson.fastmail.fm \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).