Page 1 of 1

compiler and linker problem

Posted: Mon Jun 27, 2005 11:00 pm
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

Re: compiler and linker problem

Posted: Mon Jun 27, 2005 11:00 pm
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

Re: compiler and linker problem

Posted: Mon Jun 27, 2005 11:00 pm
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.