Undefined reference to...

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
mrfrustrationman
Posts: 13
Joined: Sun Jun 14, 2020 5:15 pm
Libera.chat IRC: mrfrust

Undefined reference to...

Post by mrfrustrationman »

Hi... again, I solved the vga problem but when i include the code of cpu interrupts i get the following error from ld:
Image

my build.bat:

Code: Select all

@echo off
cls
color a
echo Compiling...
gcc -ffreestanding -c  kernel\kernel.c -o kernel\kernel.o
gcc -ffreestanding -c kernel\drivers\ports.c -o kernel\drivers\ports.o
gcc -ffreestanding -c kernel\drivers\screen.c -o kernel\drivers\screen.o
gcc -ffreestanding -c kernel\drivers\util.c -o kernel\util.o
gcc -ffreestanding -c cpu\idt.c -o cpu\idt.o
gcc -ffreestanding -c cpu\isr.c -o cpu\isr.o
timeout 2 >nul
echo Kernel dump:
objdump -d kernel\kernel.o
timeout 1 >nul
echo nasm:
nasm -f elf boot\kernel_entry.asm -o boot\kernel_entry.o
nasm -f elf cpu\interrupt.asm -o cpu\interrupt.o
echo ld:
ld -o kernel\kernel.out -Ttext 0x1000  kernel\kernel.o cpu\isr.o cpu\idt.o cpu\interrupt.o boot\kernel_entry.o kernel\drivers\ports.o kernel\drivers\screen.o kernel\util.o
echo objcopy:
objcopy -O binary kernel\kernel.out kernel\kernel.bin
echo nasm:
nasm boot\bootloader.asm -f bin -o boot\bootloader.bin
echo cat:
cat boot\bootloader.bin kernel\kernel.bin > os-image.bin
pause >nul

::qemu-system-x86_64 os-image.bin
call run.bat
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Undefined reference to...

Post by MichaelPetch »

This is another reason to use an ELF Cross Compiler. With Windows object files, the convention for 32-bit COFF files (Windows Object files) is that any function you want to make global must have an underscore prefixed to the name. If you write C code, a Windows C compiler will automatically add the extra underscore under the hood. However, in assembly code you must do this yourself! So you will need to add an `_` (underscore) to the beginning of each of the functions you wish to made available to the C code. So function `isr1` would be `_isr1` and you would also have to make it globally visible by using `global _isr1` as well. Do not add the underscores inside the C code that is handled automatically by the compiler.

Note: You seem to be using prnt.sc to publish your images. That service doesn't seem to play well with OSDev forum and the images don't actually show up. I have to go out of my way to find the link and then go to your images directly.
mrfrustrationman
Posts: 13
Joined: Sun Jun 14, 2020 5:15 pm
Libera.chat IRC: mrfrust

Re: Undefined reference to...

Post by mrfrustrationman »

MichaelPetch wrote:This is another reason to use an ELF Cross Compiler. With Windows object files, the convention for 32-bit COFF files (Windows Object files) is that any function you want to make global must have an underscore prefixed to the name. If you write C code, a Windows C compiler will automatically add the extra underscore under the hood. However, in assembly code you must do this yourself! So you will need to add an `_` (underscore) to the beginning of each of the functions you wish to made available to the C code. So function `isr1` would be `_isr1` and you would also have to make it globally visible by using `global _isr1` as well. Do not add the underscores inside the C code that is handled automatically by the compiler.

Note: You seem to be using prnt.sc to publish your images. That service doesn't seem to play well with OSDev forum and the images don't actually show up. I have to go out of my way to find the link and then go to your images directly.
Sorry for the lightshot link, and thanks for the help!
Post Reply