Not linking

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
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Not linking

Post by moondeck »

Hi,
i am compiling my "operating system" thingie, but it stops at linking, it says

Code: Select all

kloaderasm.o: In function `irq_common_stub':
kernelld.asm:(.data+0xbb): undefined reference to `ihandler'
The code is for IRQ handling, ihandler() is in the kernelio directory.
The code for the OS is on GitHub https://github.com/m00nd3ck/hydrogen
What did i do wrong?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Not linking

Post by gerryg400 »

The ihandler function is defined in irq.c. According to your Makefile you aren't compiling or linking that file.
If a trainstation is where trains stop, what is a workstation ?
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Not linking

Post by moondeck »

gerryg400 wrote:The ihandler function is defined in irq.c. According to your Makefile you aren't compiling or linking that file.
Oh ****, thanks :D Derp me :D
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Not linking

Post by Octocontrabass »

In addition, the options you're passing to gcc don't look quite right (you don't need -m32 but you do need -lgcc) and you're directly calling ld to link your kernel instead of using gcc.
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Not linking

Post by moondeck »

Octocontrabass wrote:In addition, the options you're passing to gcc don't look quite right (you don't need -m32 but you do need -lgcc) and you're directly calling ld to link your kernel instead of using gcc.
Thanks,what is wrong with calling ld?
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Not linking

Post by Octocontrabass »

There isn't really anything wrong with it (gcc calls ld when you link your program), but it makes things easier since you can use the same options for both compiling and linking.
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Not linking

Post by moondeck »

Octocontrabass wrote:There isn't really anything wrong with it (gcc calls ld when you link your program), but it makes things easier since you can use the same options for both compiling and linking.
Thanks, now i am getting another error

Code: Select all

kernelio/irq.c:66:5: error: too many arguments to function 'init_irq_handler'
     init_irq_handler(47, (unsigned)irq15, 0x08, 0x8E);
I have commited the new code to the repo
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Not linking

Post by gerryg400 »

Let me fill in the gaps.

Your made an error in the file "kernelio/irq.c:" on line "66" at the ":5":th character. The "error:" is that you passed "too many arguments to" the "function 'init_irq_handler'".
If a trainstation is where trains stop, what is a workstation ?
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Not linking

Post by moondeck »

gerryg400 wrote:Let me fill in the gaps.

Your made an error in the file "kernelio/irq.c:" on line "66" at the ":5":th character. The "error:" is that you passed "too many arguments to" the "function 'init_irq_handler'".
yes, but i have used code from Bran's tutorial, and i thought it would work.
The definition of init_irq_handler is

Code: Select all

void init_irq_handler(int irq, void (*handler)(struct regs *r))
{
    irqrout[irq] = handler;
}
but for some reason its usage is

Code: Select all

init_irq_handler(32, (unsigned)irq0, 0x08, 0x8E);
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Not linking

Post by iansjack »

moondeck wrote:yes, but i have used code from xxxx's tutorial, and i thought it would work.
A classic beginner's mistake. Never just copy code from somewhere else, without understanding it, and then complain that it doesn't work.
User avatar
moondeck
Member
Member
Posts: 56
Joined: Sat Dec 19, 2015 12:18 pm
Libera.chat IRC: moondeck
Location: The Zone, Chernobyl

Re: Not linking

Post by moondeck »

iansjack wrote:
moondeck wrote:yes, but i have used code from xxxx's tutorial, and i thought it would work.
A classic beginner's mistake. Never just copy code from somewhere else, without understanding it, and then complain that it doesn't work.
Yeah, i understood what it does, but there were some unexplained things there.
For example:

Code: Select all

init_irq_handler(32, (unsigned)irq0, 0x08, 0x8E);
what are the 0x08, 0x8E there for? i have removed them, and it compiles normally, without triple faulting. i will try to make it actually do something
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Not linking

Post by BrightLight »

moondeck wrote:

Code: Select all

init_irq_handler(32, (unsigned)irq0, 0x08, 0x8E);
what are the 0x08, 0x8E there for? i have removed them, and it compiles normally, without triple faulting. i will try to make it actually do something
0x08 is probably your code segment. 0x8E tells the CPU this IDT entry is present, requires a descriptor priviledge 0, and is an i386 interrupt gate.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: Not linking

Post by mikegonta »

moondeck wrote:
Octocontrabass wrote:In addition, the options you're passing to gcc don't look quite right (you don't need -m32 but you do need -lgcc) and you're
directly calling ld to link your kernel instead of using gcc.
Thanks,what is wrong with calling ld?
Octocontrabass wrote:There isn't really anything wrong with it (gcc calls ld when you link your program), but it makes things easier since you can use
the same options for both compiling and linking.
Personally, I prefer to link separately during development. That way I can concentrate on getting it to compile without concern for
getting it to link just yet. I use a Windows command script, I know a make file is better, however the script allows me more control
(and easier for me to customize). For example (coming from an asm background) I option gcc to output a listing which the script
opens in a text editor. After linking, the binary is then copied to a live USB flash drive which is emulated by Qemu.
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Not linking

Post by Octocontrabass »

mikegonta wrote:Personally, I prefer to link separately during development.
You can still link separately even when using GCC to link.
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: Not linking

Post by FusT »

moondeck wrote:Yeah, i understood what it does, but there were some unexplained things there.
You are contradicting yourself there.
I'm not trying to offend you but I think you haven't got the faintest idea what that code is actually doing or how the C language and compiler work.
GCC is actually your friend when it comes to errors, it usually is pretty clear about what mistakes you made and where you made them, you just need to understand them..
What omarrx024 said should have been clear to you before you started writing/copy-pasting code.

I strongly suggest you read http://wiki.osdev.org/Beginner_Mistakes and catch up on some theory so you understand why and how things are the way they are.

OSdev is hard but doable. just don't give up :wink:
Post Reply