2

Im following a tutorial on how to create an OS from scratch. I'm at the point where I need to start writing code in C but I need to compile it, in free standing mode, to raw binary. The commands given are:

gcc -ffreestanding -c kernel.c -o kernel.o
ld -o kernel.bin -Ttext 0x1000 kernel.o --oformat binary

The first command works, the second doesn't. OSX's linker doesn't know anything about -Ttext. Anyone know a way around this without using a virtual linux system? There must be a way.

objcopy doesn't work either.

Chuck Onwuzuruike
  • 344
  • 1
  • 4
  • 12
  • 3
    I'm not sure why you think there must be a way. Apple doesn't encourage such things. Where are you planning to run this program? Have you considered whether the GNU BinUtils can be compiled on/for macOS (Mac OS X)? I've not tried it recently; I don't recall whether I tried it in times past or not. – Jonathan Leffler Dec 18 '16 at 03:15
  • Thanks, I looked into it – Chuck Onwuzuruike Dec 18 '16 at 20:25

1 Answers1

2

I downloaded the GNU utils using homebrew and that came with gobjcopy which I used. I got the download information from here: https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/

I just pasted all the installatoin commands into a .sh file and ran it.

The commands I ended up using after installing were:

gcc -ffreestanding -c kernel.c -o kernel.o
gobjcopy -O binary kernel.o kernel.bin
Chuck Onwuzuruike
  • 344
  • 1
  • 4
  • 12