Need help with multiple C files

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Need help with multiple C files

Post by moondeck »

So, can anyone help me with this error after compiling the kernel with my cross compiler?

Code: Select all

nasm -f elf32 kernelld.asm -o k.o
i686-elf-gcc -m32 -c kernelio/kernelio.c
i686-elf-gcc -m32 -c kernel.c
i686-elf-gcc -m32 -o kernel_main.o kernel.o kernelio.o
/home/moondeck/ccompiler/lib/gcc/i686-elf/5.3.0/../../../../i686-elf/bin/ld: cannot find crt0.o: No such file or directory
/home/moondeck/ccompiler/lib/gcc/i686-elf/5.3.0/../../../../i686-elf/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
makefile:2: recipe for target 'kernel' failed
make: *** [kernel] Error 1
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: Need help with multiple C files

Post by Combuster »

Roman wrote:Remove "-m32", add "-ffreestanding".
A kernel is not an userspace application. You'll probably want a linker script as well.
"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 ]
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Need help with multiple C files

Post by moondeck »

Combuster wrote:
Roman wrote:Remove "-m32", add "-ffreestanding".
A kernel is not an userspace application. You'll probably want a linker script as well.
I do have a linker script, i think i have included it in the first post, didnt i?
EDIT: Nope, its here:

Code: Select all

OUTPUT_FORMAT(elf32-i386)
ENTRY(begin)
SECTIONS
 {
   . = 0x100000;
   .text : { *(.text) }
   .data : { *(.data) }
   .bss  : { *(.bss)  }
 }
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: Need help with multiple C files

Post by Combuster »

What good is a linker script if you're not using it? :wink:

Also, you made the Strings do not work beginner mistake.
"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 ]
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Need help with multiple C files

Post by moondeck »

Combuster wrote:What good is a linker script if you're not using it? :wink:

Also, you made the Strings do not work beginner mistake.
How can i not be using it if its in my makefile?

Code: Select all

kernel:
	nasm -f elf32 kernelld.asm -o k.o
	i686-elf-gcc -m32 -c kernelio/kernelio.c
	i686-elf-gcc -m32 -c kernel.c
	i686-elf-gcc -m32 -o kernel_main.o kernel.o kernelio.o
	i686-elf-ld -m elf_i386 -T kernel.ld -o kernel k.o kernel_main.o
Also, the code WORKED before a part of it to kernelio.c and using a cross compiler.
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: Need help with multiple C files

Post by Combuster »

Have you ever manually used a linker on the command line for any reasonably-sized project? You don't seem to understand how the process of compiling and linking is supposed to work (hint: your makefile calls the linker twice).

In addition, I hardly see you fix anything mentioned so far.
"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 ]
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Need help with multiple C files

Post by moondeck »

Combuster wrote:Have you ever manually used a linker on the command line for any reasonably-sized project? You don't seem to understand how the process of compiling and linking is supposed to work (hint: your makefile calls the linker twice).

In addition, I hardly see you fix anything mentioned so far.
Nope, never used it, i dont really know how it should be configured. I have only programmed microcontrollers before, and it did not require manual linking
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Need help with multiple C files

Post by iansjack »

Combuster wrote:(hint: your makefile calls the linker twice).
To be strictly accurate, it will only ever call the linker once, but there are two entries for the linker in the makefile.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Need help with multiple C files

Post by Roman »

You should learn, how your tools work. Take a look at the gcc man page.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Post Reply