From: Sebastien on
Hi,

I'm a new developper in Ada, and I found out a really suprising and
unknown language. I have a read a lot of stuff on internet, made many tests.

Now there is only one things I didn't get information about.

I'd like to create a share object in Ada and use it in an Ada software.

So the question is, is the ads file going to be enough to get my program
compile?

For instance:

with mylibpkg;
procedure Main is
begin
mylibpkg.Print();
end Main;

I have only the mylibpkg.so and the mylibpkg.ads, can I compile?

ldd main is going to me dependent of mylibpkg.so?

Thanks by advance,
Sebastien

From: Georg Bauhaus on
Sebastien wrote:
> Hi,
>
> I'm a new developper in Ada, and I found out a really suprising and
> unknown language. I have a read a lot of stuff on internet, made many
> tests.
>
> Now there is only one things I didn't get information about.
>
> I'd like to create a share object in Ada and use it in an Ada software.

I suppose you are referring to dynamic linking at the OS level?
In this case you need to import functions from the library, perhaps
using pragma Import. Also, have a look at descriptions of the Ada
package hierarchy "Interfaces".

The imported functions will have to match subprogram declarations
in your package mylibpkg.

The documentation that came with your compiler should explain
the switches needed for linking with shared libraries.
From: Sebastien on
> I suppose you are referring to dynamic linking at the OS level?

Yes I am.

> In this case you need to import functions from the library, perhaps
> using pragma Import. Also, have a look at descriptions of the Ada
> package hierarchy "Interfaces"

But it's for interfacing with other languages, isn't it?
The point is I don't want to interface with some other language, I want
to create Shared object in Ada and then link with this shared object

> The imported functions will have to match subprogram declarations
> in your package mylibpkg.

So you mean that if I use the pragma export in my ads file, everything
is going to be fine?

For instance:
function My_Ada_Function return Integer is begin
return 1;
end My_Ada_Function;
pragma Export
(Convention => C,
Entity => My_Ada_Function,
External_Name => "My_Ada_Function" );

Or will I have to get two ads file? One with the pragma Export to create
the shared object, and then one with the Pragma import to use the shared
object in my program?

> The documentation that came with your compiler should explain
> the switches needed for linking with shared libraries.

Yes I think I can find out by myself especially because I'm using gnat ;-)

Sebastien

From: Ludovic Brenta on
Sebastien writes:
> Now there is only one things I didn't get information about.
>
> I'd like to create a share object in Ada and use it in an Ada software.

Since you mentioned .ads files I assume you use GNAT on GNU/Linux or
*BSD. In that case your best source of information is the GNAT User's
Guide, chapter 19 "GNAT and Libraries":

http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gnat_ugn_unw/GNAT-and-Libraries.html

HTH

--
Ludovic Brenta.
From: Sebastien on
> Since you mentioned .ads files I assume you use GNAT on GNU/Linux or
> *BSD. In that case your best source of information is the GNAT User's
> Guide, chapter 19 "GNAT and Libraries":
>
> http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gnat_ugn_unw/GNAT-and-Libraries.html

Yes I'm running Gnat on FreeBSD.
Thanks about this link, I didn't know.

Sebastien