Error linking when including header files with barebones

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.
Post Reply
billy
Posts: 1
Joined: Sun Oct 29, 2023 1:24 pm

Error linking when including header files with barebones

Post by billy »

Hello.

I've followed the barebones tutorial and got it to run in qemu. Now i'm trying to put some code in another file, test.{h,c}, but i get an error linking. There are no errors/messages compiling kernel.c. The error i get is:

Code: Select all

/home/billy/opt/cross/lib/gcc/i686-elf/13.2.0/../../../../i686-elf/bin/ld: ../obj/kernel.o: in function `kernel_main':
kernel.c:(.text+0x445): undefined reference to `TestFunc'
collect2: error: ld returned 1 exit status
and the command i'm running is

Code: Select all

i686-elf-gcc -T ../linker.ld -o ../bin/kernel.bin -ffreestanding -O2 -nostdlib ../obj//kernel.o -lgcc
Everything else is the same as the barebones tutorial.
Any help would be appreciated.

Thanks!
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Error linking when including header files with barebones

Post by klange »

You are building a separate object file and then not including it when you link. You must include all object files in your final link.
Post Reply