I'm trying to learn operation system using i386-elf-gcc on my mac pro. Os version is Sierra. I use Macports to install the compile environment by typing sudo port install i386-elf-gcc
in bash. But when I compile a helloworld program it goes wrong.
gcc hello.c
/opt/local/lib/gcc/i386-elf/4.7.2/../../../../i386-elf/bin/ld: cannot find crt0.o: No such file or directory
collect2: error: ld returned 1 exit status
then I use sudo find / -name "crt0.o"
, but in my mac there only has crt1.o, crt3.o and so on. And I use -nostdlib and -nostartfiles it still goes wrong:
gcc -nostdlib -nostartfiles hello.c
/opt/local/lib/gcc/i386-elf/4.7.2/../../../../i386-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000008048054
/var/folders/wc/0c_zn09x12s_y90ccmvjb6900000gn/T//cc384VWr.o: In function `main':
hello.c:(.text+0x11): undefined reference to `puts'
collect2: error: ld returned 1 exit status
crt0.o
, then you have to provide your own startup code defining_start
(that's for the second problem). – Moravian-nostdlib
and-nostartfiles
unless you have a really good reason (which happens in .000001% of cases). – MediatoryMach-O 64-bit object x86_64
orMach-O object i386
, neither of which is self-evidently ELF-compatible. What are you expecting to happen? – Autochthonous