Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find crt0.o: No such file or directory

Tags:

c

macos

gcc

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
like image 501
wind2412 Avatar asked Jan 30 '26 08:01

wind2412


1 Answers

ASSUMPTION: If you'e learning operating systems, I assume you are trying to write a bootable code of some sort, and that would be the reason why you're trying to pass -nostdlib and -nostartfiles.

My answer lies on that assumption.

One of the problems in the second output (the -nostdlib -nostartfiles command) is that you are trying to use a libc function puts() and probably hasn't implemented it. So the linker cannot find its byte code to generate the final executable.

While I cannot provide an explanation for the first message with the information available, I can speculate that something is missing or wrong with your libc. It's either not matching your compiler somehow, or absent, or something like this.

Furthermore, if you're writing bootable code you are likely going to need a linker script. Your firmware has specific standards on where in memory the entry point of your program will be loaded and where it needs to start execution, and you'll need your linker script to organize the final binary according to this layout.

like image 183
Ágatha Isabelle Avatar answered Feb 01 '26 21:02

Ágatha Isabelle