In fact there is a linker under GNU/Linux. It is called ld
. But the linking step must be done using the gcc
as a linker. Attempt to call ld
directly on our relocatable object module files will fail:
$ ld hello.o banner.o ld: warning: cannot find entry symbol _start; defaulting to 0000000008048094 banner.o(.text+0xe): In function 'NewLine': : undefined reference to 'putchar' banner.o(.text+0x3d): In function 'GenerateStars': : undefined reference to 'printf' banner.o(.text+0x5a): In function 'GenerateStars': : undefined reference to 'printf' banner.o(.text+0xa4): In function 'GenerateBanner': : undefined reference to 'printf' banner.o(.text+0xbe): In function 'GenerateBanner': : undefined reference to 'putchar' $ _
This failure comes from the fact that the object module files themselves are not enough to produce a working executable. We need also some routines from the standard C library. In the MS-DOS example the linker (which comes in the compiler software package and thus works closely with the compiler) searches the standard C library automatically, but in GNU/Linux it does not. The gcc
command invokes the linker with additional command line options that tells it to search the standard C library as well as the object module files given by the user.