Creating Flat Binary with Cygwin (NASM + C)

Programming, for all ages and all languages.
Post Reply
Geometrian
Member
Member
Posts: 77
Joined: Tue Nov 20, 2012 4:45 pm
Contact:

Creating Flat Binary with Cygwin (NASM + C)

Post by Geometrian »

I'm trying to write a very basic kernel. I have a .asm file that jumps to a function in a .c file. I'm trying to compile these into a flat binary (.bin) under Cygwin.

I've run into so many errors and tried so many different things, it's not even funny.

The most reasonable thing I've tried:

Code: Select all

nasm.exe jump.asm -f elf32 -o jump.o

gcc.exe -c -m32 -Wall -Wextra -Werror -nostdlib -fno-builtin -nostartfiles -nodefaultlibs kernel.c -o kernel.o

ld.exe -m elf_i386 -s -r --oformat binary --entry jump jump.o kernel.o -o kernel.bin
It produces:

Code: Select all

Assembler messages:
Fatal error: selected target format 'pe-i386' unknown
and

Code: Select all

C:\dev\Perl\c\bin\ld.exe: unrecognised emulation mode: elf_i386
Supported emulations: i386pep
What are the correct flags for everything?

Thanks,
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Creating Flat Binary with Cygwin (NASM + C)

Post by Combuster »

Use the proper tools.
GCC Cross-Compiler
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply