Undefined reference to assembly function

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
User avatar
MuchLearning
Member
Member
Posts: 26
Joined: Sun Feb 12, 2017 1:50 am

Undefined reference to assembly function

Post 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?
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Undefined reference to assembly function

Post by dozniak »

You have not defined a label outb: in your asm file.
Learn to read.
User avatar
MuchLearning
Member
Member
Posts: 26
Joined: Sun Feb 12, 2017 1:50 am

Re: Undefined reference to assembly function

Post by MuchLearning »

dozniak wrote:You have not defined a label outb: in your asm file.
...it is late

Thank you
Post Reply