0

I am following the tutorial at https://littleosbook.github.io/ and wanted to understand whether or not what I have currently working is conceptually correct. In terms of where I am at, I am using macOS 10.15.7 for the development and was able to call a C function from the loader. The loader is in assembly. However, I used the Clang compiler (Apple clang version 12.0.0) to compile the C file in which the aforementioned C function is. Then, I compiled the C file to generate an object file and linked the .o file with loader.o

Is this how it should be done? Or should I be trying to firstly install gcc or clang inside the OS and have that compiler compile the C function for me?

  • You need a cross-compiler which runs on your host, but compiles the code for the target. – Eugene Sh. Nov 17 '20 at 19:40
  • It really depends what executable format you want coming out the other end. If you can deal with the macOS [Mach-O](https://en.wikipedia.org/wiki/Mach-O) format, you're set. If not, you need a different compiler. – tadman Nov 17 '20 at 19:41
  • macOS is an `x86` CPU [at present ;-)]. If the target system you want to build for is _also_ an `x86`, you can probably use the host compiler [possibly with some extra options] (e.g. you want to test this under a VM or emulator like `qemu`). If you were compiling for a different target architecture (e.g. arm [`aarch64`]), you would need the correct cross-compiler and build tools. – Craig Estey Nov 17 '20 at 19:44
  • 1
    To get your OS to a sufficient level that it can run something like clang or gcc is a huge task. What you're doing (using another system to compile) is just fine. – Mat Nov 17 '20 at 19:45
  • You can get by at the beginning with your normal compiler, but see this: https://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler%3F – user253751 Nov 17 '20 at 19:53

0 Answers0