How can I use GCC to Compile Flat Binary files (*.c, *.cpp)

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
billy87

How can I use GCC to Compile Flat Binary files (*.c, *.cpp)

Post by billy87 »

ok... I am very new to OSdev and I was wondering how to get a simple *.cpp or *.c file compiled to a flat binary file for my bootloader to run at startup.. I have very little experience with C and CPP, but i have been programming in ASM for several months now. thx in advance ;)
uri

RE:How can I use GCC to Compile Flat Binary files (*.c, *.cp

Post by uri »

compile all your c-code like this:

gcc -c -o a.o a.c
gcc -c -o b.o b.c

you'll get a bunch of object files. link those together using ld:

ld --oformat binary -Ttext 0x100000 -o mykernel.bin a.o b.o

this instructs ld to create a flat binary file called mykernel.bin that has to be loaded at 1 MB. if you prefer a different loading address, change the value after Ttext.
common

RE:How can I use GCC to Compile Flat Binary files (*.c, *.cp

Post by common »

You could also add -e <function_name> to add an entry point to your new binary.
Post Reply