The Place to Start for Operating System Developers
It is currently Fri Aug 07, 2020 3:04 am

All times are UTC - 6 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [Help] LD is saying undefined reference.
PostPosted: Thu Jan 24, 2019 11:08 pm 

Joined: Thu Jan 24, 2019 10:51 pm
Posts: 1
Hey guys,

It's been about eight years since I last did anything OS Dev related, and I want to get back into it. I'm taking baby steps to refresh my memory; however, I'm running into an issue with linking that I can't figure out. Whenever I try to link my object files, I get this error in the terminal:
start.o: In function `stublet':
start.asm:(.text+0x29): undefined reference to `_main'

I'm running 64-bit Linux Mint in Parallels on Mac OS X.

I have start.asm with this snippet of code:
     extern _main
     call _main
     jmp $

To compile the asm file, I'm using this:
nasm -f elf64 -o start.o start.asm

void main(){

To compile main.c, I'm using these arguments:
gcc -Wall -o -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c

Finally, to link them, I'm using this:
ld -T linker.ld -o kernel.bin start.o main.o

Is the error caused to the way I'm compile my ASM, linking my files, or the way I'm calling an external function from Assembly?

Thanks for all the help! It's going to take a little bit to get back in the grove of things.

I'm also going based off of Bran's Kernel Development guide (figured that might be a decent place to start with a memory refresher)... although, a lot of it seems questionable. Does anyone have any opinions on that guide?

 Post subject: Re: [Help] LD is saying undefined reference.
PostPosted: Fri Jan 25, 2019 12:03 am 
User avatar

Joined: Mon Jul 13, 2009 5:52 am
Posts: 99
Location: Denmark
Hi GermanSensation,

In your asm file you should probably remove the underscores and simply call "main" instead of "_main". With that being said, I have two more comments.

First, you should build a proper cross compiler, as this will make your life easier in the future. Have a look here: https://wiki.osdev.org/GCC_Cross-Compiler

Bran's Kernel Development guide is known to contain bugs, so be careful about using it. The wiki has a list of known bugs (but the list might not be exhaustive): https://wiki.osdev.org/Bran%27s_Known_Bugs

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Google [Bot] and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group