This is the mail archive of the
mailing list for the Cygwin project.
Re: GCC : -static option does not generate statically linked executable
- From: Charles Wilson <cwilson at ece dot gatech dot edu>
- To: T-FERNANDEZ at dassault-data-services dot fr
- Cc: cygwin at cygwin dot com
- Date: Wed, 05 Dec 2001 13:25:33 -0500
- Subject: Re: GCC : -static option does not generate statically linked executable
- References: <OF49EA1364.67B4844C-ONC1256B19.0055088C@dds.fr>
> I am trying to generate an executable, using "gcc -static" option.
> The generated file is dynamically linked! As if the "-static" option was
> simply ignored.
> The output of "cygcheck" is as follows :
> Error: could not find libX11.dll
> One can see that the X11 DLL library is not found : however, I use the
> -static option of gcc, before the -lX11 stuff, as mentioned in the
> I expect the compiler to link against libX11.a, so what happens?
> Any idea would be greatly appreciated,
-static will cause the linker to link against a static lib IF POSSIBLE.
However, it really just means "hunt for '.a' instead of '.dll.a' or
.dll.a == import lib for a dll
.dll == the linker has a limited ability to link directly to a dll
*without* using an import lib.
.a == static lib (mostly *)
(*) The problem: many packages -- including X -- name their *import*
libs using the .a suffix. So, when you specify -static, the linker
diligently links against the .a file == an import lib == and you get a
dynamically linked executable.
When this sort of behavior happens, it's usually becuase there IS no
static library at all -- you CAN'T link statically. (The X libraries
are a good example; cygwin-xfree project does NOT provide static libs.)
Also, note that you can't link a cygwin program *fully* statically -- at
minimum, it will require cygwin1.dll...
As far as your particular "can't find libX11.dll" problem -- add
/usr/X11R6/bin to your system PATH.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html