Paul B Mahol said:
On 9/28/10, Anton Shterenlikht <me...@bristol.ac.uk> wrote:
> > I'm trying to learn the very basics of the
> > compile - assemble - link process on FreeBSD.
> > Please don't shoot me.
> ....
> > Then I try to link the object file into
> > an executable:
> >
> > % ld tmp.o
> 
> You are missing something in above command.
> 

More precisely, if you run gcc -v on a C file you get someting like:
 /usr/bin/ld --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1
/usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib
-L/usr/lib /var/tmp//cco5EINk.o -lgcc --as-needed -lgcc_s --no-as-needed
-lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o
/usr/lib/crtn.o


where the object file produced by compilation and assembling is 
/var/tmp//cco5EINk.o 

That is adds several other object files to your own in order to get 
an executable.

In particular the start symbol, at which execution begins is in 
/usr/lib/crt1.o

as you can see from
niobe% nm /usr/lib/crt1.o
         w _DYNAMIC
00000000 D __progname
         U _fini
         U _init
         U _init_tls
00000000 T _start
00000020 t _start1
00000000 r abitag
         U atexit
00000004 C environ
         U exit
         U main
which shows that _start is defined here, (but not e.g. _init). On the
other hand the function main() which is defined in your program is 
referred to but undefined here.


-- 

Michel TALON

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to