Linking error - undefined references

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.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Linking error - undefined references

Post by abcdef4bfd »

I'm tried to implement IDT & ISRs for my OS. I known that it requires a lot of assembly code, added it to other .asm file, compiled and linked it. But ld is gived me errors.
kernel.cpp:(.text+0x4971): undefined reference to 'isr0()'
Lots of this errors is appeared. I think that the problem is in my link command:

Code: Select all

i686-elf-ld -T link.ld -o os365.bin -O2 -nostdlib idt.o boot.o kernel.o
And, more global, any assembly code in separate files is not linking for me.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Linking error - undefined references

Post by Roman »

And, more global, any assembly code in separate files is not linking for me.
Perhaps you miss using the .globl directive?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

Roman wrote:
And, more global, any assembly code in separate files is not linking for me.
Perhaps you miss using the .globl directive?
No, i'm written in ASM code that:

Code: Select all

global isr0
; 0 to 31.
global isr31
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Linking error - undefined references

Post by Roman »

And how do you build your assembly file?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

Roman wrote:And how do you build your assembly file?
yasm idt.asm -o idt.o -f elf32
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Linking error - undefined references

Post by Techel »

Since magic isn't discovered yet you should post your linker script, I bet, so we can help you in the way we can check it and reply.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

Roflo wrote:Since magic isn't discovered yet you should post your linker script, I bet, so we can help you in the way we can check it and reply.
It's the same as in the Bare Bones tutorial.

Code: Select all

ENTRY(_start)
SECTIONS
{
	. = 1M;
	.text BLOCK(4K) : ALIGN(4K)
	{
		*(.multiboot)
		*(.text)
	}
	.rodata BLOCK(4K) : ALIGN(4K)
	{
		*(.rodata)
	}
	.data BLOCK(4K) : ALIGN(4K)
	{
		*(.data)
	}
	.bss BLOCK(4K) : ALIGN(4K)
	{
		*(COMMON)
		*(.bss)
		*(.bootstrap_stack)
	}
}
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Linking error - undefined references

Post by Roman »

How does the assembly code look like?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

Roman wrote:How does the assembly code look like?
It's from Bran's kernel development tutorial.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Linking error - undefined references

Post by Techel »

So it is exactly the same? Then it are the tools from where the problem came.
And, keep in mind, the c++ compiler is not very kind. It will mangle the symbols in a way its not easy detecting such errors, I can say.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Linking error - undefined references

Post by Combuster »

It's the same as in the Bare Bones
It's from Bran's kernel development tutorial.
Shame on you for mix&matching tutorials, and then complaining here because you can't even sort out the simple things such as an undefined symbol, as it is basically the first error you encounter as a C developer when you make a typo.

The solution is in every case a homework exercise:
- Which source file or library should have that symbol? Does it? Really?
- Which object file should have that symbol? Does it? Really?
- Are you actually adding it in the linking process?

My crystal ball says you failed at both #1 and #3.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

Combuster wrote:
It's the same as in the Bare Bones
It's from Bran's kernel development tutorial.
Shame on you for mix&matching tutorials, and then complaining here because you can't even sort out the simple things such as an undefined symbol, as it is basically the first error you encounter as a C developer when you make a typo.

The solution is in every case a homework exercise:
- Which source file or library should have that symbol? Does it? Really?
- Which object file should have that symbol? Does it? Really?
- Are you actually adding it in the linking process?

My crystal ball says you failed at both #1 and #3.
1) idt.asm, and really haves it.
2) idt.o.
3) Adding.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Linking error - undefined references

Post by Techel »

Your c++ compiler, when referring to 'idt0()', will import it as a mangled symbol, eg 'xz164_v0idt0' or something like this. Use 'extern "c"' to import it as '_idt0'. Then you also have to change your asm file to export '_idt0'.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Linking error - undefined references

Post by abcdef4bfd »

Roflo wrote:Your c++ compiler, when referring to 'idt0()', will import it as a mangled symbol, eg 'xz164_v0idt0' or something like this. Use 'extern "c"' to import it as '_idt0'. Then you also have to change your asm file to export '_idt0'.
Tried your method, not working for me. Can you give me your linker script, please?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Linking error - undefined references

Post by Combuster »

Roflo wrote:Use 'extern "c"' to import it as '_idt0'. Then you also have to change your asm file to export '_idt0'.
Why are you still not using a crosscompiler?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply