Page 1 of 1

Undefined References

Posted: Thu Jun 16, 2005 6:16 pm
by linguae
Hello. I'm working on building an operating system, and I'm following the Bran's Kernel Development Tutorial (located at http://www.osdever.net/bkerndev/index.php?the_id=90). I'm pretty much laying down the bricks now; I have a very long way to go before I have a POSIX-compatible multitasking microkernel operating system running all of these great applications.

Anyways, I have reached the stage to where I have written the output drivers in the tutorial. However, I have trouble compiling the kernel. Here is my output:

Code: Select all

Now assembling, compiling, and linking your kernel: 
scrn.c: In function `scroll':
scrn.c:24: warning: passing arg 1 of `memcpy' from incompatible pointer type
scrn.c:24: warning: passing arg 2 of `memcpy' from incompatible pointer type
start.o(.text+0x2d): In function `stublet':
: undefined reference to `_main'
scrn.o(.text+0x45): In function `scroll':
: undefined reference to `memcpy'
scrn.o(.text+0x259): In function `putch':
: undefined reference to `memcpy'
Done!
I know what the warnings mean, but I don't know what "undefined reference to `___'" means.

My code is attached to a zip file since it is too long to put in this post.

I am new to all of this, so I don't know what is going wrong. Thanks in advance.

Re:Undefined References

Posted: Thu Jun 16, 2005 6:20 pm
by linguae
Oops, my zip file is here.

Re:Undefined References

Posted: Thu Jun 16, 2005 6:41 pm
by mystran
You have done the same typo I did yesterday: your memcpy function is implemented with the name 'memcopy' :)

You also see the infamous underscore issue: you are compiling your C-code on a platform on which the C-compiler doesn't add underscore in front of symbols, but your assembler source calls _main and not main. Just get rid of the underscore.

I didn't bother to figure out why you get the warnings. You probably need an explicit cast to get rid of them.

Re:Undefined References

Posted: Thu Jun 16, 2005 7:25 pm
by GLneo
o, dont beat your self up, everyone started once, here i'll help,
1.) i'll organize your folders
2.) give you a make.bat ready for the future with wild card link ;D
3.) give you my custom bootsector so you don't have to wory about grub :P
4.) the make boot gives you an image (.img) ready for testing ;)
enjoy ;D

Re:Undefined References

Posted: Thu Jun 16, 2005 7:38 pm
by GLneo
sorry cant post makeboot (too big)
you'll have to compile it your self(simple) ;)

Re:Undefined References

Posted: Fri Jun 17, 2005 1:31 am
by Solar
Meta explanation (mystran and GLneo gave good hints, but perhaps you are actually confused about the error message, not only the reasons for it):

"Undefined reference to ..." happens during the linking process, and means that a function or variable declared as "extern" cannot be found in any of the object files involved in the linking.

mystran did point out the typo you did in main.c (memcopy()). Since scrn.c, line 24, refers to memcpy() (without 'o'), that reference cannot be resolved, and no binary be created because the linker cannot find any executable code for a function called memcpy.

HTH.

Re:Undefined References

Posted: Fri Jun 17, 2005 2:28 am
by Candy
Solar wrote: "Undefined reference to ..." happens during the linking process, and means that a function or variable declared as "extern" cannot be found in any of the object files involved in the linking.
The most common occurrences of this I see are:
- Not linking along all object files / not using all the code you've written
- Forgetting to actually code a function, but still using it
- Not putting a static class member definition in the code file
- Using a different name than is actually being defined, and having declarations for both

Other than these four and those that Solar mentioned, more complex causes are probably going on.

Re:Undefined References

Posted: Fri Jun 17, 2005 7:42 am
by GLneo
the main problem was the memcopy - memcpy, but his wasn't linking main.o + scrn.o, so i include the working ".bat"