comp.lang.ada
 help / color / mirror / Atom feed
* Static linking
@ 2009-08-07  7:54 Markus Schoepflin
  2009-08-07 10:15 ` Ludovic Brenta
  2009-08-12 14:20 ` Alex R. Mosteo
  0 siblings, 2 replies; 7+ messages in thread
From: Markus Schoepflin @ 2009-08-07  7:54 UTC (permalink / raw)


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?

Markus



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Static linking
  2009-08-07  7:54 Static linking Markus Schoepflin
@ 2009-08-07 10:15 ` Ludovic Brenta
  2009-08-07 10:46   ` Markus Schoepflin
  2009-08-12 14:20 ` Alex R. Mosteo
  1 sibling, 1 reply; 7+ messages in thread
From: Ludovic Brenta @ 2009-08-07 10:15 UTC (permalink / raw)


Markus Schoepflin wrote on comp.lang.ada:
> 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?

libc6 does not exist as a static library anymore; on GNU/Linux there
is no way to create a completely static executable; you have to link
against (at least) libc.so.6 dynamically.  So, the executable you
obtain with -bargs -static is as static as you can get :)

>  > 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?

I don't know and it seems strange to me that it worked at all if the
binder was not called with -static. Maybe others on comp.lang.ada have
more to tell us?

--
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Static linking
  2009-08-07 10:15 ` Ludovic Brenta
@ 2009-08-07 10:46   ` Markus Schoepflin
  0 siblings, 0 replies; 7+ messages in thread
From: Markus Schoepflin @ 2009-08-07 10:46 UTC (permalink / raw)
  To: Ludovic Brenta

Ludovic Brenta wrote:
> Markus Schoepflin wrote on comp.lang.ada:

[...]

>> 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?
> 
> libc6 does not exist as a static library anymore; on GNU/Linux there
> is no way to create a completely static executable; you have to link
> against (at least) libc.so.6 dynamically.  So, the executable you
> obtain with -bargs -static is as static as you can get :)

Now I'm really confused. The command just below your answer in my original 
mail works and gives me a static executable:

>>  > 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
>>

[...]

Markus



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Static linking
  2009-08-07  7:54 Static linking Markus Schoepflin
  2009-08-07 10:15 ` Ludovic Brenta
@ 2009-08-12 14:20 ` Alex R. Mosteo
  1 sibling, 0 replies; 7+ messages in thread
From: Alex R. Mosteo @ 2009-08-12 14:20 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* static linking
@ 2014-10-04  1:19 agent
  2014-10-04  7:21 ` Simon Wright
  0 siblings, 1 reply; 7+ messages in thread
From: agent @ 2014-10-04  1:19 UTC (permalink / raw)


Hi.  I have written a small ada  pgm under ubuntu.  This program is
working.  But it only works on computers that I have already installed
gnat.  I am assuming that this is due to dynamic linking to a runtime
library for ada.

Is there a way to statically link an ada program so I do not have this
issue?

Thanks

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: static linking
  2014-10-04  1:19 static linking agent
@ 2014-10-04  7:21 ` Simon Wright
  2014-10-04 18:10   ` agent
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Wright @ 2014-10-04  7:21 UTC (permalink / raw)


agent@drrob1.com writes:

> Hi.  I have written a small ada  pgm under ubuntu.  This program is
> working.  But it only works on computers that I have already installed
> gnat.  I am assuming that this is due to dynamic linking to a runtime
> library for ada.
>
> Is there a way to statically link an ada program so I do not have this
> issue?

   $ gnatbind --help
   ...
     -static   Link against a static GNAT run time
     -shared   Link against a shared GNAT run time
   ...

   $ gnatmake foo.adb -bargs -static

(I guess -shared is default on your system; on Mac OS X it appears the
default is -static).


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: static linking
  2014-10-04  7:21 ` Simon Wright
@ 2014-10-04 18:10   ` agent
  0 siblings, 0 replies; 7+ messages in thread
From: agent @ 2014-10-04 18:10 UTC (permalink / raw)


On Sat, 04 Oct 2014 08:21:01 +0100, Simon Wright <simon@pushface.org>
wrote:

>
>> Hi.  I have written a small ada  pgm under ubuntu.  This program is
>> working.  But it only works on computers that I have already installed
>> gnat.  I am assuming that this is due to dynamic linking to a runtime
>> library for ada.
>>
>> Is there a way to statically link an ada program so I do not have this
>> issue?
>
>   $ gnatbind --help
>   ...
>     -static   Link against a static GNAT run time
>     -shared   Link against a shared GNAT run time
>   ...
>
>   $ gnatmake foo.adb -bargs -static
>
>(I guess -shared is default on your system; on Mac OS X it appears the
>default is -static).

Thanks.  That worked.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-10-04 18:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-07  7:54 Static linking Markus Schoepflin
2009-08-07 10:15 ` Ludovic Brenta
2009-08-07 10:46   ` Markus Schoepflin
2009-08-12 14:20 ` Alex R. Mosteo
  -- strict thread matches above, loose matches on Subject: below --
2014-10-04  1:19 static linking agent
2014-10-04  7:21 ` Simon Wright
2014-10-04 18:10   ` agent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox