This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -static not working with gcc 4.3.4


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]