How to link object file with library to generate new relocatable object file

Nick Clifton nickc@redhat.com
Wed Feb 18 14:31:00 GMT 2009


Hi Will,

> I am trying to link object files and libraries to generate new object file

Why ?  I am just curious ?  What benefit do you get from creating a new 
object file rather than, say, just adding object files into the already 
existing library ?

> But when I try to link an object file which uses external function with the
> library contains the function code with '-r' option, the library function
> code will not be included in the output object file.

This should work.

> For example, I have a C source file named 'foo.c' in which there is a
> function 'A' invokes a library function 'B'. Then I use the command below to
> generate object file contain the code of function B:
> 
> gcc -o foo.o foo.c
> ld -r -o newobj.o foo.o -lmylib

I tried this and my version of newobj.o did contain both the code for 
function A (from foo.o) and the code for function B (from mylib).

This was on an x86 Linux target using the current version of the 
binutils.  What host/tools did you use ?

Cheers
   Nick



More information about the Binutils mailing list