Cross compiler can't find newlib crt0.o

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
codyd51
Member
Member
Posts: 77
Joined: Fri May 20, 2016 2:29 pm
Location: London, UK
GitHub: https://github.com/codyd51
Contact:

Cross compiler can't find newlib crt0.o

Post by codyd51 »

Hello!

I apologize if this is a simple question, but I can't seem to figure it out; I ported Newlib to my OS following the guide on the wiki, and am trying to compile a file with i686-elf-gcc. This is the command I'm compiling with:

Code: Select all

./i686-toolchain/bin/i686-elf-gcc -I$SYSROOT/usr/include -L$SYSROOT/usr/lib -lc -lgcc $SYSROOT/usr/lib/crt0.o test.c -o test.elf
When I run this, i686-elf/bin/ld complains "cannot find crt0.o: No such file or directory".

$SYSROOT/usr/lib/ctr0.o exists, as you'd expect. It doesn't seem to have any trouble finding $SYSROOT/usr/lib/libc.a, which as you can see I'm linking against.

Am I missing something simple? Thanks!
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: Cross compiler can't find newlib crt0.o

Post by dchapiesky »

How did you port newlib to your OS without creating a newlib/libc/sys/TARGET directory?

Where TARGET is your os name...?

Examine newlib/libc/sys/rtems for an example of an crt0.c

files in newlib/libc/sys are compiled only when you use a triplet such as i686-elf-rtems....

also - did you compile you cross compiler with --with-newlib?
Plagiarize. Plagiarize. Let not one line escape thine eyes...
codyd51
Member
Member
Posts: 77
Joined: Fri May 20, 2016 2:29 pm
Location: London, UK
GitHub: https://github.com/codyd51
Contact:

Re: Cross compiler can't find newlib crt0.o

Post by codyd51 »

dchapiesky wrote:How did you port newlib to your OS without creating a newlib/libc/sys/TARGET directory?

Where TARGET is your os name...?

Examine newlib/libc/sys/rtems for an example of an crt0.c

files in newlib/libc/sys are compiled only when you use a triplet such as i686-elf-rtems....

also - did you compile you cross compiler with --with-newlib?
I did create a newlib/libc/sys/{my os} directory; I ported newlib by following this wiki page: http://wiki.osdev.org/Porting_Newlib

I did not compile my cross compiler with --with-newlib.
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: Cross compiler can't find newlib crt0.o

Post by dchapiesky »

Thank you for the extra information....


The simplest solution is to simply compile an empty crt0.c and include it in your link line. This implies that you are using a ld script and an elf loader for your kernel where either _start() or main() are specified as your entry point.

The next solution is to modify your ld script to not include crt0.o as part of the link....

Another solution is to add a crt0.c to your newlib sys directory newlib/libc/sys/myos - this is worth while as it allows you to have an entry point _start() while giving you control of how main() is called - useful for setting up stdin/stdout etc.... make sure you run the autotools to properly reconfigure your build scripts

finally the hardest solution - but well worth it - is to go full http://wiki.osdev.org/OS_Specific_Toolchain where in the section called gcc/config/myos.h you can customize your start file specs using STARTFILE_SPEC

This is by far the most useful of all examples as it allows you to compile other software packages you didn't develop without having to hack their makefiles to add your ld script.
Plagiarize. Plagiarize. Let not one line escape thine eyes...
Post Reply