[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: undefined reference to `main' and strange gnat behaviour

Gour wrote:
starting with Ada by reading English's Craft 95 and Barnes 95 books...

These are both excellent starting points.  Especially John English
is more accessible to beginners IMHO.

$ gnatmake hello.adb
gnatbind -x hello.ali
gnatlink hello.ali
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o: In function `_start': /build/glibc-irh9iM/glibc-2.19/csu/../sysdeps/x86_64/start.S:118: undefined reference to `main'
collect2: error: ld returned 1 exit status
gnatlink: error when calling /usr/bin/gcc-4.9
gnatmake: *** link failed.

I'll try to reproduce that later and report back. This is the first time I saw this.

$ ls -al
total 52
drwxr-xr-x 1 gour gour   134 Ruj 23 13:03 ./
drwxr-xr-x 1 gour gour   118 Ruj 21 17:30 ../
-rw-r--r-- 1 gour gour  8382 Ruj 23 13:03 b~hello.adb
-rw-r--r-- 1 gour gour 13401 Ruj 23 13:03 b~hello.ads
-rw-r--r-- 1 gour gour  7763 Ruj 23 13:03 b~hello.ali
-rw-r--r-- 1 gour gour   657 Ruj 23 13:03 b~hello.o
-rw-r--r-- 1 gour gour   117 Ruj 23 13:03 hello.adb
-rw-r--r-- 1 gour gour  1487 Ruj 23 13:03 hello.ali
-rw-r--r-- 1 gour gour   657 Ruj 23 13:03 hello.o

What's wrong and what are those b~hello.? generated files?

The b~* files are Ada source files generated by the binder (gnatbind)
and then compiled by the linker (gnatlink) before inclusion in your
executable file.  You can look at them if you want.  They contain the
instructions to perform elaboration, i.e. the code that is executed
before "begin", like elaboration of "withed" packages, creation and
initialization of local variables, etc.  Since hello.adb contains
your program's entry point, b~hello.adb contains (or should contain)
the function "main" called by crt1.o, and which calls your procedure

Come to think of it, are you really sure hello.adb contains a
procedure and not a package?

Ludovic Brenta.

Ludovic Brenta.

Reply to: