This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RE: How to link object file with library to generate new relocatable object file
- From: "Hotmail" <will7125 at hotmail dot com>
- To: "'Nick Clifton'" <nickc at redhat dot com>
- Cc: <binutils at sources dot redhat dot com>
- Date: Thu, 19 Feb 2009 11:05:19 +0800
- Subject: RE: How to link object file with library to generate new relocatable object file
- References: <BAY113-DS57D7EFD2D2FF4F628A0EED0BD0@phx.gbl> <499C1BB4.6010509@redhat.com>
Hi Nick,
Thanks for your reply!
> > 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 ?
>
I am thinking about adding plug-in to my embedded system which does not have
program loader and linker. So the solution mostly comes from the Linux
loadable module mechanism. To provide convenience to the plug-in developer,
I want to add Standard C library support for the plug-in development. All
these things bring up the question.
Also, do you have any idea about this?
> > 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.
Yes, it works. I tried this again and got the expected result. I am not
really sure why this did not work for the first time but I cannot find the
sample code that I used in my first try. I think maybe I forgot to include
the header file or something like that.
>
> > 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?
I am using a cross-toolsets with the host of x86 Linux and target for arm
bare board which was compiled by myself.
Again, thanks for your time to answer my question.
Will