How to link against newlib?

Jeff Johnston jjohnstn@redhat.com
Mon Jul 9 21:54:00 GMT 2012


On 06/29/2012 06:12 PM, Christian Haake wrote:
> Hi there,
> this is my first post so I apologize if my question is a duplicate...
> Currently I'm trying to implement the sbrk() system call which is used
> by malloc. For this in the syscalls.c file I included a header file
> called pagealloc.h.
> But while compiling I get a "undefined reference" error because the
> associated object file will not be linked.
> So my question is how to tell newlib which object file to link with.
> Should I customize a Makefile and if yes, which one and how?!?
> Thanks in advance for your help.
> Chris
>

You're going to have to elaborate a lot more.

What platform are you configuring for?  Are you adding a new platform 
and if so, did you create a libgloss library?

For new platforms, it is recommended you create a libgloss library to 
support syscalls.

You have some choices after that.  A number of platforms provide an ld 
script in libgloss which knows how to link a particular libgloss 
library.  That makes it easy to compile/link - the -T option of gcc is 
used to specify the name of the ld script.

See the libgloss/mn10300 directory for an example of an ld script that 
is set up for a simulator (sim.ld).

If your compiler builds multi-libs, then the newlib build will build 
multiple versions of the libraries with different options.  It is 
recommended you link the newlib/libgloss directories into your gcc 
check-out and make them siblings of the gcc directory so you can 
build/install gcc, newlib, and libgloss together.  When you compile/link 
with that gcc, it will automatically figure out the path to the 
multi-libs that are appropriate for the gcc options you have chosen. 
Otherwise, you can manually specify the path to the appropriate 
libgloss/newlib libraries but that is more difficult.

See the newlib FAQ found at sourceware.org/newlib for pointers on 
porting and a link to the crossgcc FAQ.

-- Jeff J.



More information about the Newlib mailing list