newlib - undefined references

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
justin
Member
Member
Posts: 43
Joined: Sun Jan 11, 2009 2:09 pm

newlib - undefined references

Post 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.
justin
Member
Member
Posts: 43
Joined: Sun Jan 11, 2009 2:09 pm

Re: newlib - undefined references

Post 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.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: newlib - undefined references

Post 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.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: newlib - undefined references

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
justin
Member
Member
Posts: 43
Joined: Sun Jan 11, 2009 2:09 pm

Re: newlib - undefined references

Post 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.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: newlib - undefined references

Post 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.
Post Reply