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.
Post Reply
linguae

Undefined References

Post 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.
linguae

Re:Undefined References

Post by linguae »

Oops, my zip file is here.
mystran

Re:Undefined References

Post 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.
GLneo

Re:Undefined References

Post 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
GLneo

Re:Undefined References

Post by GLneo »

sorry cant post makeboot (too big)
you'll have to compile it your self(simple) ;)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Undefined References

Post 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.
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Undefined References

Post 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.
GLneo

Re:Undefined References

Post by GLneo »

the main problem was the memcopy - memcpy, but his wasn't linking main.o + scrn.o, so i include the working ".bat"
Post Reply