Page 1 of 1
Linker undefined reference cross compiling
Posted: Sat Sep 28, 2013 10:42 pm
by therll
I was following Bran's tutorial (
http://www.osdever.net/bkerndev/Docs/intro.htm) and the linker would always give me undefined reference errors. It looked a something like this:
isrs.o: In function `isrs_install':
isrs.c:(.text+0x3e): undefined reference to `isr0'
isrs.c:(.text+0x51): undefined reference to `isr1'
isrs.c:(.text+0x67): undefined reference to `isr2'
irq.o: In function `irq_install':
irq.c:(.text+0x105): undefined reference to `irq0'
irq.c:(.text+0x118): undefined reference to `irq1'
irq.c:(.text+0x12e): undefined reference to `irq2'
irq.c:(.text+0x141): undefined reference to `irq3'
I'm developing on Ubuntu 12.04 32 bit in a virtual machine so I don't think I need a cross compiler.
I saw that there was a post about this (
http://f.osdev.org/viewtopic.php?t=20375&p=160670) but I couldn't find an answer there.
Any ideas?
Re: Linker undefined reference cross compiling
Posted: Sun Sep 29, 2013 1:35 am
by bwat
I know this sounds bad, and at first glance may not seem very helpful, but linking problems like these are not difficult at all so the problem is more than likely your knowledge of how the build tool-chain works. Solve that problem first, then this other problem with missing symbols will be easy to diagnose and fix. You need to hit the manual pages. Just go through all the steps in the build process, one at a time, and look at the input being given to each step. The manual pages will tell you how to get this information.
Re: Linker undefined reference cross compiling
Posted: Sun Sep 29, 2013 4:07 am
by sortie
I'm developing on Ubuntu 12.04 32 bit in a virtual machine so I don't think I need a cross compiler.
Topic name: Linker undefined reference cross compiling
Stop! You are not cross-compiling. The gcc on your Ubuntu 12.04 32 bit produces executables for your Ubuntu 12.04 32 bit system: It doesn't produce executables for your custom operating system, no matter how similar they are. Additionally, the gcc on your distribution may have applied nasty patches that don't play nice with osdev work (you don't know, because you haven't checked). You ought to be in control of your toolchain and spending a little time to set up a safe GCC that knows it targets something custom is much work it. Additionally, a lot of tutorials that fool you into using a non-cross-compiler use a lot of compiler switches to cover up their mistake and forget to link in libgcc (which you must). Search my earlier forum posts for more rationale.
Please follow this tutorial to set up a GCC cross-compiler for i586-elf:
http://wiki.osdev.org/GCC_Cross-Compiler
Please follow this tutorial to see how to use the cross-compiler and what compiler options are recommended (delete other options that you don't know what does):
http://wiki.osdev.org/Bare_Bones
Unfortunately, our Wiki does not cover all the subjects that Bran's tutorial does in a friendly how-to manner - however, it's not horribly outdated like that tutorial. My advise is to
discard what you got, follow the Bare Bones tutorial, then integrate parts of the Bran tutorial that don't conflict with wiki.osdev.org advise, and slowly rebuild your OS.
The reason your problem is happening is because Bran is
not using a cross-compiler but rather misuses a Windows compiler. This means that extern "C" symbols have a single underscore prepended. However, you are attempting to use a System V ABI compiler, where symbols do not have an underscore prepended. This means that the linker is looking for 'isr0', but your assembly file provides '_isr0'. The root of this problem is that you are not using the same compiler as Bran was. The solution to fix your problems is to follow the current wiki.osdev.org advise and follow older tutorials with extreme mistrust.
Re: Linker undefined reference cross compiling
Posted: Sun Sep 29, 2013 1:13 pm
by therll
I followed the instructions for cross-compiling binutils and GCC and it worked, but it was a bit confusing before because when it said "You need to use a cross-compiler unless you are developing on your own operating system" I thought that I was developing for my own operating system and so I kept trying without one...
Re: Linker undefined reference cross compiling
Posted: Sun Sep 29, 2013 1:21 pm
by Owen
unless you are developing on your own operating system
Re: Linker undefined reference cross compiling
Posted: Sun Sep 29, 2013 1:23 pm
by bluemoon
therll wrote:You need to use a cross-compiler unless you are developing on your own operating system
Note the
on your own operating system, it means self hosted toolchains.
Oops, owen is quicker.