Page 1 of 1

Undefined reference to assembly function

Posted: Sun Apr 16, 2017 2:48 am
by MuchLearning
I have a function written in assembly and I am trying to access it from C through a header file.

I have 2 files, io.s and io.h

Code: Select all

.intel_syntax noprefix

.global outb
.type outb, @function
mov al, [esp+8]
mov dx, [esp+4]
out dx, al
ret

Code: Select all

#include <stddef.h>

void outb(size_t port, size_t data);
I'm inluding io.h in another file, terminal.c, but when trying to link I get an "undefined reference to outb" error.

Code: Select all

i686-elf-as io.s -o io.o
i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o terminal.o io.o -lgcc
terminal.o: In function `terminal_move_cursor':
terminal.c:(.text+0x61): undefined reference to `outb'
terminal.c:(.text+0x81): undefined reference to `outb'
terminal.c:(.text+0x98): undefined reference to `outb'
terminal.c:(.text+0xb1): undefined reference to `outb'
collect2: error: ld returned 1 exit status
What am I doing wrong?

Re: Undefined reference to assembly function

Posted: Sun Apr 16, 2017 3:00 am
by dozniak
You have not defined a label outb: in your asm file.

Re: Undefined reference to assembly function

Posted: Sun Apr 16, 2017 3:06 am
by MuchLearning
dozniak wrote:You have not defined a label outb: in your asm file.
...it is late

Thank you