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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1a80a77402b27e77 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!news.motzarella.org!motzarella.org!not-for-mail From: =?ISO-8859-1?Q?S=E9bastien?= Newsgroups: comp.lang.ada Subject: Re: Shared library in Ada Date: Mon, 21 Apr 2008 10:09:19 +0000 Organization: A noiseless patient Spider Message-ID: References: <87od86jc3j.fsf@ludovic-brenta.org> <878wzaj751.fsf@ludovic-brenta.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: feeder.motzarella.org U2FsdGVkX1/PszTTEnK0NccIvP7ObHK1wuTyq/g9mKxbMUlDTXxWHfAQcnyIfmTIJ/R+nxEKWHT2Z6EMbp0DaqV0ooXyShKE5BGVf3ka48X/vsmH5lxNi4cyr/OxbxVnoLrFeC5e7Vugmes+E7u6yQ== X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Mon, 21 Apr 2008 10:07:26 +0000 (UTC) In-Reply-To: <878wzaj751.fsf@ludovic-brenta.org> X-Auth-Sender: U2FsdGVkX1+nldkukqAah6J+aj54niuYlmYuXgvkOLkAd1n54NzjaA== Cancel-Lock: sha1:o+5stezo1uB4oQIit9T/+c7HTIQ= User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) Xref: g2news1.google.com comp.lang.ada:21010 Date: 2008-04-21T10:09:19+00:00 List-Id: Thanks for you help, it's working fine. Sebastien > Sebastien writes: >>> Yes I'm running Gnat on FreeBSD. >>> Thanks about this link, I didn't know. >> I follow the instruction and did the sample thing: > > [snipped] > > - Since both your library and your test program are in Ada, you don't > need pragma Import or pragma Export. > > - You do not need to duplicate the mylib.ads file. > > - If you're going to use project files, you should go all the way and > define a library project file for your library, and use that to > build the library. > > The library: > > package My_Lib is > pragma Preelaborate; > procedure Print; > end My_Lib; > > with Ada.Text_IO; > package body My_Lib is > procedure Print is > begin > Ada.Text_IO.Put_Line ("Hello, World."); > end Print; > end My_Lib; > > project My_Lib is > for Source_Dirs use ("my_lib"); > for Object_Dir use "my_lib.o"; > for Library_Name use "mylib"; > for Library_Kind use "dynamic"; > for Library_Dir use "lib"; > for Externally_Built use "false"; > end My_Lib; > > You then build the library like this: > > gnatmake -Pmy_lib > > This will produce ./lib/libmylib.so. > > Then, the client: > > with My_Lib; > procedure Main is > begin > My_Lib.Print; > end Main; > > with "my_lib"; > project Main is > for Source_Dirs use ("."); > for Main use ("main"); > end Main; > > You would build your client program like this: > > gnatmake -Pmain > > which will link main dynamically with lib/libmylib.so. > > Sebastien writes: >>> Yes I'm running Gnat on FreeBSD. >>> Thanks about this link, I didn't know. >> I follow the instruction and did the sample thing: > > [snipped] > > - Since both your library and your test program are in Ada, you don't > need pragma Import or pragma Export. > > - You do not need to duplicate the mylib.ads file. > > - If you're going to use project files, you should go all the way and > define a library project file for your library, and use that to > build the library. > > The library: > > package My_Lib is > pragma Preelaborate; > procedure Print; > end My_Lib; > > with Ada.Text_IO; > package body My_Lib is > procedure Print is > begin > Ada.Text_IO.Put_Line ("Hello, World."); > end Print; > end My_Lib; > > project My_Lib is > for Source_Dirs use ("my_lib"); > for Object_Dir use "my_lib.o"; > for Library_Name use "mylib"; > for Library_Kind use "dynamic"; > for Library_Dir use "lib"; > for Externally_Built use "false"; > end My_Lib; > > You then build the library like this: > > gnatmake -Pmy_lib > > This will produce ./lib/libmylib.so. > > Then, the client: > > with My_Lib; > procedure Main is > begin > My_Lib.Print; > end Main; > > with "my_lib"; > project Main is > for Source_Dirs use ("."); > for Main use ("main"); > end Main; > > You would build your client program like this: > > gnatmake -Pmain > > which will link main dynamically with lib/libmylib.so. >