comp.lang.ada
 help / color / mirror / Atom feed
* Undefined reference errors and strange new files appearing
@ 2014-06-21 22:21 hreba
  2014-06-22  5:56 ` Dmitry A. Kazakov
  2014-06-22 20:50 ` Simon Wright
  0 siblings, 2 replies; 10+ messages in thread
From: hreba @ 2014-06-21 22:21 UTC (permalink / raw)


Hi,

Still struggling to get a foot into Ada.

I wrote a simple abstract linear list library,  "gen-lists", and a test 
programs test_genlists which uses it. The files are:

   gen-lists.ads		abstract linear list
   gen-lists.adb
   test_lists_aux.ads	concrete extension of the list
   test_lists_aux.adb
   test_lists.adb	main subprogram

The project file gen.gpr for the library is

---------------------------------------------------------------------
library project Gen is

    for Library_Name use "Gen";

    for Library_Dir use "../All";
    for Source_Dirs use ("src");
    for Object_Dir use "obj";

    package Compiler is
       for Default_Switches ("ada") use ("-gnatf", "-gnato", "-gnat05", 
"-g");
    end Compiler;

end Gen;
---------------------------------------------------------------------

and test_genlists.gpr for the test program:

---------------------------------------------------------------------
with "../../gen.gpr";

project Test_Genlists is

    for Main use ("test_lists.adb");

    package Compiler is
       for Default_Switches ("ada") use ("-g", "-gnatf", "-gnat05");
    end Compiler;

    package Linker is
       for Default_Switches ("ada") use ("-g");
    end Linker;

end Test_Genlists;
---------------------------------------------------------------------

Now "gnatmake -Ptest_genlists" gets me

---------------------------------------------------------------------
gcc-4.6 -c -g -gnatf -gnat05 -I- -gnatA 
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists.adb
gcc-4.6 -c -gnatf -gnato -gnat05 -g -I- -gnatA 
/home/frank/Lib/Ada/Gen/src/gen.ads
gcc-4.6 -c -gnatf -gnato -gnat05 -g -I- -gnatA 
/home/frank/Lib/Ada/Gen/src/gen-lists.adb
gcc-4.6 -c -g -gnatf -gnat05 -I- -gnatA 
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists_aux.adb

building static library for project gen
ar cr /home/frank/Lib/Ada/All/libGen.a 
/home/frank/Lib/Ada/Gen/obj/gen-lists.o ...
ranlib /home/frank/Lib/Ada/All/libGen.a
gnatbind -I- -x /home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists.ali
gnatlink /home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists.ali -g 
-L/home/frank/Lib/Ada/All/ -lGen -o 
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists
b~test_lists.o: In function `adainit':
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/b~test_lists.adb:158: 
undefined reference to `gen__lists___elabs'
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/b~test_lists.adb:159: 
undefined reference to `gen__lists_E'
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists_aux.o: In 
function `test_lists_aux__itemdIP':
test_lists_aux.adb:(.text+0x2b): undefined reference to 
`gen__lists__itemdIP'
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists_aux.o: In 
function `test_lists_aux__itemdSR':
test_lists_aux.adb:(.text+0x65): undefined reference to 
`gen__lists__itemdSR'
/home/frank/Lib/Ada/Gen/tests/Test_gen-lists/test_lists_aux.o: In 
function `test_lists_aux__itemdSW':
test_lists_aux.adb:(.text+0x99): undefined reference to 
`gen__lists__itemdSW'
...
--------------------------------------------------------------------

The 3 dots mean a bunch of further error messages. Besides this, the new 
files

   b~test_lists.adb  b~test_lists.ads  b~test_lists.ali  b~test_lists.o

appear out of nowhere.

I guess I forgot something in the project files. Nevertheless I 
reproduce the start of my sources:

gen-lists.ads:
-------------------------------------------------------------------
-- Abstract linear lists

package Gen.Lists is

    -- the list and its primitive operations

    type ItemD is abstract tagged private;
    type Item is access all ItemD'Class;
    type List is limited private;

    function IsEmpty (l: List) return boolean;
    function Next (i: access ItemD) return Item;
    procedure Append (l: in out List; i: Item);
    ...
-------------------------------------------------------------------

gen-lists.adb:
-------------------------------------------------------------------
--Abstract linear lists

package body Gen.Lists is

    -- primitive list operations

    function IsEmpty (l:List) return Boolean is
    begin return l.first=null;
    end IsEmpty;


    function Next (i:access ItemD) return Item is
    begin return i.next;
    end Next;


    procedure Append (l: in out List; i:Item) is
    begin
       if l.first=null then l.first:= i; else l.last.next:= i; end if;
       l.last:= i;
    end Append;
    ...
--------------------------------------------------------------------

test_lists_aux.ads:
--------------------------------------------------------------------
-- Test of Gen.Lists

with Gen.Lists;

package test_lists_aux is

    type ItemD is new Gen.Lists.ItemD with
       record
          ch:	Character;
       end record;
    type Item is access all ItemD;

    function NewItem (c: Character) return Item;
    ...
-------------------------------------------------------------------

test_lists_aux.adb:
-------------------------------------------------------------------
with Ada.Text_IO;	use Ada.Text_IO;

package body test_lists_aux is

function NewItem (c: Character) return Item is
    i: Item;
begin
    i:= new ItemD;
    i.ch := c;
    return i;
end NewItem;
...
-------------------------------------------------------------------

test_lists.adb:
-------------------------------------------------------------------
-- Test of Gen.Lists

with Ada.Text_IO;  use Ada.Text_IO;
with Gen.Lists;
with test_lists_aux;

procedure Test_Lists is
    a, b, c, d, e:	test_lists_aux.Item;
    list:		Gen.Lists.List;
begin
    -- print header
    Put_Line("");
    Put_Line ("Test of Gen.Lists");
    Put_Line ("-----------------");
    -- create list
    a:= test_lists_aux.NewItem ('a');
    b:= test_lists_aux.NewItem ('b');
    c:= test_lists_aux.NewItem ('c');
    d:= test_lists_aux.NewItem ('d');
    e:= test_lists_aux.NewItem ('e');
    Gen.Lists.Append (list, Gen.Lists.Item(a));
    Gen.Lists.Append (list, Gen.Lists.Item(b));
    ...
-----------------------------------------------------------------

What am I doing wrong?

-- 
Frank Hrebabetzky		+55 / 48 / 3235 1106
Florianopolis, Brazil

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

* Re: Undefined reference errors and strange new files appearing
  2014-06-21 22:21 Undefined reference errors and strange new files appearing hreba
@ 2014-06-22  5:56 ` Dmitry A. Kazakov
  2014-06-22  9:04   ` Georg Bauhaus
                     ` (2 more replies)
  2014-06-22 20:50 ` Simon Wright
  1 sibling, 3 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2014-06-22  5:56 UTC (permalink / raw)


On Sat, 21 Jun 2014 19:21:52 -0300, hreba wrote:

> Still struggling to get a foot into Ada.
> 
> I wrote a simple abstract linear list library,  "gen-lists", and a test 
> programs test_genlists which uses it. The files are:
> 
>    gen-lists.ads		abstract linear list
>    gen-lists.adb
>    test_lists_aux.ads	concrete extension of the list
>    test_lists_aux.adb
>    test_lists.adb	main subprogram
> 
> The project file gen.gpr for the library is
[...]
> I guess I forgot something in the project files. Nevertheless I 
> reproduce the start of my sources:

Did you build your library? Usually, when using a library as an OS library,
you need two projects, one in order to build the library and another to use
it. Then each projects would likely have several scenarios depending on
whether the library is relocatable or static (and debugging or release).

P.S. b~files are generated by GNAT when building an executable. Ignore
them.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

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

* Re: Undefined reference errors and strange new files appearing
  2014-06-22  5:56 ` Dmitry A. Kazakov
@ 2014-06-22  9:04   ` Georg Bauhaus
  2014-06-22 16:08     ` hreba
  2014-06-22 15:51   ` hreba
  2014-06-22 20:43   ` Simon Wright
  2 siblings, 1 reply; 10+ messages in thread
From: Georg Bauhaus @ 2014-06-22  9:04 UTC (permalink / raw)


On 22/06/14 07:56, Dmitry A. Kazakov wrote:
> P.S. b~files are generated by GNAT when building an executable. Ignore
> them.

Better still, learn why you can ignore them, from the
GNAT User's Guide accompanying your distribution; the reasons
are stated in some introductory sections that illustrate
GNAT's translation processes.



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

* Re: Undefined reference errors and strange new files appearing
  2014-06-22  5:56 ` Dmitry A. Kazakov
  2014-06-22  9:04   ` Georg Bauhaus
@ 2014-06-22 15:51   ` hreba
  2014-06-22 20:06     ` Dmitry A. Kazakov
  2014-06-22 20:43   ` Simon Wright
  2 siblings, 1 reply; 10+ messages in thread
From: hreba @ 2014-06-22 15:51 UTC (permalink / raw)


On 06/22/2014 02:56 AM, Dmitry A. Kazakov wrote:
>
> Did you build your library? Usually, when using a library as an OS library,
> you need two projects, one in order to build the library and another to use
> it. Then each projects would likely have several scenarios depending on
> whether the library is relocatable or static (and debugging or release).
>
> P.S. b~files are generated by GNAT when building an executable. Ignore
> them.
>

Yes, I built the library. I do not really need an OS library, I just 
thought that this is the only way to compile something without a main 
subprogram in it. I found extensive documentation (GBRbuild User's Guide 
in /usr/share/doc/gprbuild-doc/html/gprbuild_ug.html) on how to build a 
library and very little on how to import it.

So what is the usual development cycle of a project without a main 
subprogram (called "library" below)? The following?

1. Write the project file of the "library", be it as library or not.

2. Write an application (test-) project which imports the "library".

3. Compile the application in order to debug the imported "library".
    Iterate this step.

4. When the "library" is sufficiently mature, and if a real library is 
wanted, compile it as a library project.

Up to now, I always have been compiling my libraries on its own in order 
to correct syntactical errors, only then I switched to (test-) 
applications importing them.

-- 
Frank Hrebabetzky		+55 / 48 / 3235 1106
Florianopolis, Brazil

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

* Re: Undefined reference errors and strange new files appearing
  2014-06-22  9:04   ` Georg Bauhaus
@ 2014-06-22 16:08     ` hreba
  0 siblings, 0 replies; 10+ messages in thread
From: hreba @ 2014-06-22 16:08 UTC (permalink / raw)


On 06/22/2014 06:04 AM, Georg Bauhaus wrote:
> On 22/06/14 07:56, Dmitry A. Kazakov wrote:
>> P.S. b~files are generated by GNAT when building an executable. Ignore
>> them.
>
> Better still, learn why you can ignore them, from the
> GNAT User's Guide accompanying your distribution; the reasons
> are stated in some introductory sections that illustrate
> GNAT's translation processes.
>

Found it. Thanks.
-- 
Frank Hrebabetzky		+55 / 48 / 3235 1106
Florianopolis, Brazil


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

* Re: Undefined reference errors and strange new files appearing
  2014-06-22 15:51   ` hreba
@ 2014-06-22 20:06     ` Dmitry A. Kazakov
  2014-06-22 20:30       ` hreba
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2014-06-22 20:06 UTC (permalink / raw)


On Sun, 22 Jun 2014 12:51:09 -0300, hreba wrote:

> On 06/22/2014 02:56 AM, Dmitry A. Kazakov wrote:
>>
>> Did you build your library? Usually, when using a library as an OS library,
>> you need two projects, one in order to build the library and another to use
>> it. Then each projects would likely have several scenarios depending on
>> whether the library is relocatable or static (and debugging or release).
>>
>> P.S. b~files are generated by GNAT when building an executable. Ignore
>> them.
> 
> Yes, I built the library. I do not really need an OS library, I just 
> thought that this is the only way to compile something without a main 
> subprogram in it.

You can always compile any file using gcc, gnatmake, gprbuild, GPS.

> I found extensive documentation (GBRbuild User's Guide 
> in /usr/share/doc/gprbuild-doc/html/gprbuild_ug.html) on how to build a 
> library and very little on how to import it.

It is still unclear if "library" means:

1. An OS-library such as *.lib, *.a, *.dll, *.so?

2. A set of Ada's library-level packages organized in a separate project,
yet not producing an OS-library?

For #2, you just make a plain Ada project (not a library project as you
did).

You refer to that project from the test project ("with" it). Then you open
the test project and you will see the referenced project and all its files
in the GPS' project view in a separate folder.

You can edit, compile these files the same way you do test project files.
When you build the test project they are automatically compiled as
necessary.

> Up to now, I always have been compiling my libraries on its own in order 
> to correct syntactical errors, only then I switched to (test-) 
> applications importing them.

You can do all work using the test project. No need to switch projects.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


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

* Re: Undefined reference errors and strange new files appearing
  2014-06-22 20:06     ` Dmitry A. Kazakov
@ 2014-06-22 20:30       ` hreba
  0 siblings, 0 replies; 10+ messages in thread
From: hreba @ 2014-06-22 20:30 UTC (permalink / raw)


On 06/22/2014 05:06 PM, Dmitry A. Kazakov wrote:
> On Sun, 22 Jun 2014 12:51:09 -0300, hreba wrote:
>
>> On 06/22/2014 02:56 AM, Dmitry A. Kazakov wrote:
>>>
>
> It is still unclear if "library" means:
>
> 1. An OS-library such as *.lib, *.a, *.dll, *.so?
>
> 2. A set of Ada's library-level packages organized in a separate project,
> yet not producing an OS-library?
>
> For #2, you just make a plain Ada project (not a library project as you
> did).
>
> You refer to that project from the test project ("with" it). Then you open
> the test project and you will see the referenced project and all its files
> in the GPS' project view in a separate folder.
>
> You can edit, compile these files the same way you do test project files.
> When you build the test project they are automatically compiled as
> necessary.
>
>> Up to now, I always have been compiling my libraries on its own in order
>> to correct syntactical errors, only then I switched to (test-)
>> applications importing them.
>
> You can do all work using the test project. No need to switch projects.
>

It is #2. Everything clear now. Thanks.
-- 
Frank Hrebabetzky		+55 / 48 / 3235 1106
Florianopolis, Brazil


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

* Re: Undefined reference errors and strange new files appearing
  2014-06-22  5:56 ` Dmitry A. Kazakov
  2014-06-22  9:04   ` Georg Bauhaus
  2014-06-22 15:51   ` hreba
@ 2014-06-22 20:43   ` Simon Wright
  2 siblings, 0 replies; 10+ messages in thread
From: Simon Wright @ 2014-06-22 20:43 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> Did you build your library? Usually, when using a library as an OS
> library, you need two projects, one in order to build the library and
> another to use it.

And OP has two projects, and the log he supplies shows that gnatmake has
correctly decided to

  * compile the test program using the test gpr
  * build the library using the library gpr
  * link the test program.using the test gpr

This is standard behaviour (now, at any rate; it may well have been less
helpful in the past ...); I don't see where the failures are coming
from.

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

* Re: Undefined reference errors and strange new files appearing
  2014-06-21 22:21 Undefined reference errors and strange new files appearing hreba
  2014-06-22  5:56 ` Dmitry A. Kazakov
@ 2014-06-22 20:50 ` Simon Wright
  2014-06-24  1:56   ` hreba
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Wright @ 2014-06-22 20:50 UTC (permalink / raw)


hreba <hreba@terra.com.br> writes:

> I guess I forgot something in the project files.

I'd modify test_genlists.gpr as below:

with "../../gen.gpr";

project Test_Genlists is

   for Main use ("test_lists.adb");
   for Object_Dir use ".build";     -- to keep .o etc out of sight
   for Exec_Dir use ".";            -- to have executable 'here' anyway

   package Builder is               -- not Linker
      for Default_Switches ("ada") use ("-g");
   end Builder;

   package Compiler is
      for Default_Switches ("ada") use ("-g", "-gnatf", "-gnat05");
   end Compiler;

end Test_Genlists;


> Nevertheless I reproduce the start of my sources:

But you've left off the end, which discourages us (me) from trying out
your code on our machines and (maybe) seeing the problem.

It really helps if you can produce a small *compilable* example.

See http://sscce.org


And I don't think you told us what operating system/compiler you're
using? I can see it's Unix-based.


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

* Re: Undefined reference errors and strange new files appearing
  2014-06-22 20:50 ` Simon Wright
@ 2014-06-24  1:56   ` hreba
  0 siblings, 0 replies; 10+ messages in thread
From: hreba @ 2014-06-24  1:56 UTC (permalink / raw)


On 06/22/2014 05:50 PM, Simon Wright wrote:
> hreba <hreba@terra.com.br> writes:
>
>> Nevertheless I reproduce the start of my sources:
>
> But you've left off the end, which discourages us (me) from trying out
> your code on our machines and (maybe) seeing the problem.
>

I changed my project following Dmitry's recommendations (not using 
library projects). I tried to get the faulty version out of my revision 
control system, but it seems not to be exactly the original one. It 
binds and links now without problem.

Sorry.
-- 
Frank Hrebabetzky		+55 / 48 / 3235 1106
Florianopolis, Brazil

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

end of thread, other threads:[~2014-06-24  1:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-21 22:21 Undefined reference errors and strange new files appearing hreba
2014-06-22  5:56 ` Dmitry A. Kazakov
2014-06-22  9:04   ` Georg Bauhaus
2014-06-22 16:08     ` hreba
2014-06-22 15:51   ` hreba
2014-06-22 20:06     ` Dmitry A. Kazakov
2014-06-22 20:30       ` hreba
2014-06-22 20:43   ` Simon Wright
2014-06-22 20:50 ` Simon Wright
2014-06-24  1:56   ` hreba

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