Page 1 of 1

newlib - undefined references

Posted: Mon May 14, 2012 4:11 pm
by justin
I am following the OS specific toolchain tutorial. I have built newlib and attempted to make a hello world program

Code: Select all

#include<stdio.h>
main()
{
    printf("Hello World");
}
This produces "undefined reference" errors to all of my system calls (read, write, etc.). I have followed the tutorial closely and put them in the file syscalls.c so I'm not sure why they are not being found. If I understand it correctly, they should be in a file lib.a which I cannot locate. I didn't see any errors during the make process.

EDIT:
I want to add that library functions which do not depend on system calls (e.g. atoi, strlen, strcmp) are working fine.

Re: newlib - undefined references

Posted: Mon May 14, 2012 5:52 pm
by justin
I'm trying to compile the library manually now and it looks like there must have been some errors that slipped by me during the make process. I'm resolving them now.

Re: newlib - undefined references

Posted: Tue May 15, 2012 12:23 am
by iansjack
You need to produce object files from the functions you have created and create a library from them. Then include that library in your list of libraries to link against. Alternatively, you can just use "ar" to add the object files to libc.a (for static linking). That way you just have to link against libc.

Re: newlib - undefined references

Posted: Tue May 15, 2012 2:03 am
by piranha
If you follow the OS Specific Toolchain article properly, it will create a toolchain which will compile that program no problem - no extra libraries or weird linking required. Go through the process step by step, and make sure you run the proper autoconf and autoreconf commands when needed.

Edit:
If I understand it correctly, they should be in a file lib.a which I cannot locate.
Yes. This will be created from the objects compiled in the sys/myos directory. It will be added to libc.a

-JL

Re: newlib - undefined references

Posted: Tue May 15, 2012 10:46 pm
by justin
Thanks people. I ended up following the procedure outlined by JamesM here: http://forum.osdev.org/viewtopic.php?p=113296, which is the same thing iansjack said.

I have a working C library. Feels good man.

Re: newlib - undefined references

Posted: Wed May 16, 2012 1:37 am
by iansjack
Just as a matter of interest, you don't have to go through the full process that JamesM describes. Once you have libc.a you can add, or refresh, object files to it with the command:

Code: Select all

ar -r libc.a foo.o
That way, if you make a change to foo it's very simple to update the library file.

I like to use the basic utilities at times rather than going through the full autoconf route. It's easy, efficient, and it gives me a better grasp of what is happening.