"zig cc" Cross-Compiler: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (moved User:Wesleyac/"zig cc" Cross-Compiler to "zig cc" Cross-Compiler: seems good enough now to ship it :))
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(2 intermediate revisions by 2 users not shown)
Line 11:
Start off with the standard [[Bare Bones]] setup, but use the <kbd>boot.asm</kbd> file provided in [[Bare Bones with NASM]] instructions (since Zig does not come with an assembler, just a C compiler). At that point, you can continue with [[Bare Bones]], but instead of using <kbd>i686-elf-gcc</kbd>, use the following command to build <kbd>kernel.c</kbd>:
 
<sourcesyntaxhighlight lang="bash">zig build-obj --c-source kernel.c -target i386-freestanding</sourcesyntaxhighlight>
 
This should create a <kbd>kernel.o</kbd> file, just the same as if you had used gcc.
Line 17:
When you get to the linking step, we won't be able to use <kbd>i686-elf-gcc</kbd>, but luckily, modern versions of [[LD|GNU <kbd>ld</kbd>]] are able to emulate almost any other linker, so we can use the system <kbd>ld</kbd> like so:
 
<sourcesyntaxhighlight lang="bash">ld -m elf_i386 -T linker.ld -o myos.bin boot.o kernel.o</sourcesyntaxhighlight>
 
And at that point, you can carry on with [[Bare Bones]], and you should have an operating system, compiled without having to compile your own cross-compiler!
 
[[Category:Compilers]]
[[Category:Zig]]