From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,b2796c9ed44bd3f5 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Static linking Followup-To: comp.lang.ada Date: Wed, 12 Aug 2009 16:20:43 +0200 Message-ID: <7eg1dsF2g1g4pU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: individual.net 3CWhLBLrmo9cCTbhDfWddwYgv87K+63tsIAEazQGYKUNoQNxQ= Cancel-Lock: sha1:GLgUJEh6b5B0sjdnS7vjMBWdysk= User-Agent: KNode/4.3.0 Xref: g2news2.google.com comp.lang.ada:7696 Date: 2009-08-12T16:20:43+02:00 List-Id: Markus Schoepflin wrote: > Hello, > > up to now (gcc-4.3.x) we have been happily using 'gnatmake ... -largs > -static' to create statically linked executable. This has stopped working > with 4.4: > > > touch foo.adb && gnatmake foo -largs -static > gcc-4.4 -c foo.adb > gnatbind -x foo.ali > gnatlink foo.ali -static > /usr/bin/ld: cannot find -lgnat-4.4 > collect2: ld returned 1 exit status > gnatlink: error when calling /usr/bin/gcc-4.4 > gnatmake: *** link failed. > > Now I have been told that -static is a binder, not a linker argument, and > indeed this works: > > > touch foo.adb && gnatmake foo -bargs -static > gcc-4.4 -c foo.adb > gnatbind -static -x foo.ali > gnatlink foo.ali > > But this is not a static executable: > > > ldd foo > linux-gate.so.1 => (0xb7f9e000) > libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7e2d000) > /lib/ld-linux.so.2 (0xb7f9f000) > > Looking at the manual for the binder I'm told: '-static Link against a > static GNAT run time.'. OK, so this works as advertised, no dynamic GNAT > runtime used. > > Now what is the correct way to created a static executable? This seems to > work, but is it correct? > > > touch foo.adb && gnatmake foo -bargs -static -largs -static > gcc-4.4 -c foo.adb > gnatbind -static -x foo.ali > gnatlink foo.ali -static > > ldd foo > not a dynamic executable > > And why did only passing '-largs -static' work for gcc-3.3.x? Not entirely sure is the same issue, but maybe it helps our understanding. I got also different results using some same switches when using GPL2008 and GPL2009. I opened a GAP support ticket and their reply was that some defaults had changed, but you could force the same results with explicit switches. In my case it involved mixed Ada/C++ linking and they also said that they were working on some internal cleaning that would improve the situation. There's another confusing issue in which you don't have to check the ld documentation but gcc/g++ one, which is the one getting the switches in the end. I don't know if I could quote the support reply I got but, in addition to Ludovic comment about "as static as it can be" given the shared libc library, the switches I'm using right now to control linking are: package Binder is for Default_Switches ("Ada") use ("-static"); -- -static/-shared makes the gnat runtime static or shared end Binder; package Linker is for Default_Switches ("Ada") use ("-Wl,-Bstatic", -- Starts static linking section "-lz", -- Sample libraries that I want statically linked. "-lgsl", "-lgslcblas", "-Wl,-Bdynamic", -- Starts shared linking section "-ldl" -- Sample library dynamically linked in ); end Linker; Hope this helps, Alex. > > Markus