compiler and linker problem

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
dozerl
Posts: 19
Joined: Tue May 10, 2005 11:00 pm
Location: here

compiler and linker problem

Post by dozerl »

On my Windows box i have djgpp gcc version 3.1 and ld version 2.13. Using that my kernel compiles just fine. But on my Linux box with gcc 4.0.0 and ld 2.16.1 it gives me an error saying:

kstart.o:kstart.o:(.text+0x21): undefined reference to '_main'

The code on both computers is the same. In kstart.asm I have
...
[extern _main]
call _main
...

This way works in Windows. If I take out the underscores it compiles fine under Linux but the kernel is messed up. The file kernel.bin is just a plain text file. How do I go about fixing this?

Thanks
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: compiler and linker problem

Post by carbonBased »

The underscore issue is because the COFF object file specs use a leading underscore while the ELF object file specs do not.

I believe you can still force GCC to emit a leading underscore with the -fleading-underscore.

I really don't know what you mean by "a plain text file" though... instead of an object file output, you get a text file? What's is look like?

--Jeff
dozerl
Posts: 19
Joined: Tue May 10, 2005 11:00 pm
Location: here

Re: compiler and linker problem

Post by dozerl »

Here is what is in the kernel.bin file, yeah its a text file:

Now booting
Loading Kernel [kernel ok]
Setting up GDT [GDT ok]
Enabling A20 [A20 ok]
Entering Protected Mode [CR0 set ok]

Which is what I have my puts function in main() print to the screen. But my putch function works correctly, it doesnt mess up like this. If ya need to see any code let me know.

I tired the -fleading-underscore that solves the issue of undefined reference to _main. But when I compile it, I still get the text file kernel.bin with the same text as mentioned above. Im only getting this text file (eg kernel.bin) when I compile and link with the newer versions of gcc and ld. Under Windows it works perfectly fine. As I said before I have older version on Windows. I would like to be able to work on my OS on both my Windows and Linux box. Thanks.
Post Reply