Kernel.bin not compiling correctly.

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
UnsurpassedBlaze
Posts: 10
Joined: Wed Nov 02, 2005 12:00 am
Location: Somewhere on Earth...

Kernel.bin not compiling correctly.

Post by UnsurpassedBlaze »

I have everything done with my kernel and bootloader script but when i go to compile with ld i get this error:

ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
kernel_c.o(.text+0x54):kernel_c.cpp: undefined reference to `_alloca'
kernel_c.o(.text+0x59):kernel_c.cpp: undefined reference to `__main'

Can somebody help me?

btw, I have my main kernel script in c++ and the script to start the c++ script in assembly(of course).
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Kernel.bin not compiling correctly.

Post by carbonBased »

Looks like you're not producing a binary stripped of all runtime support and startup code. In other words, you're probably linking to libcrt0.

Assuming you're using gcc, you'll want to compile with the following options enabled:
-ffreestanding
-fno-builtin
-nostdlib
-nostartfiles

Cheers,
Jeff
User avatar
UnsurpassedBlaze
Posts: 10
Joined: Wed Nov 02, 2005 12:00 am
Location: Somewhere on Earth...

Re: Kernel.bin not compiling correctly.

Post by UnsurpassedBlaze »

Now there's warnings coming from the bat file I made. Here's the complete output:
Building Pyro Kernel...
-----------------------
Compiling Video.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling String.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling Keyboard.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling kbInt.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling Interrupt.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling OStream.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling IStream.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling Support.c
Compiling Kernel_c.cpp
cc1plus: warning: "-ffreestanding" is valid for C/ObjC but not for C++
Compiling Kernel.asm
-----------------------
Creating Kernel...
ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
kernel_c.o(.text+0x54):kernel_c.cpp: undefined reference to `_alloca'
kernel_c.o(.text+0x59):kernel_c.cpp: undefined reference to `__main'
-----------------------
Kernel Built.
Press any key to continue . . .
The dashes, kernel built, and compiling files are all echos. the warnings come from the gcc compiler and it's still giving this error which is most important:
kernel_c.o(.text+0x54):kernel_c.cpp: undefined reference to `_alloca'
kernel_c.o(.text+0x59):kernel_c.cpp: undefined reference to `__main'
Yet I have NO kind of call to those methods.[/code]
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: Kernel.bin not compiling correctly.

Post by blackcatcoder »

what is _alloca?

self made memory method ?

if yes ld can't find an reference to your function!
try to make an prototype like:

unsigned long _alloca(int pages); // Prototype

the same with _main ?

or you call an C-function from asm ?

then use in the asm file if you use nasm :

Extern _main
call _main
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Kernel.bin not compiling correctly.

Post by dave »

Are you by chance using cygwin?

If so I had similar problems and ended up moving to a linux distro as the cygwin development tools seem to have some issuses. The issues were with ld mainly but the gcc flags also did not appear to take effect.

You need the following flags ( as posted earlier ) for gcc
-ffreestanding
-fno-builtin
-nostdlib
-nostartfiles

if you are using cygwin i would recommend trying some other dev tools or maybe a different version of cygwin.

dave
User avatar
UnsurpassedBlaze
Posts: 10
Joined: Wed Nov 02, 2005 12:00 am
Location: Somewhere on Earth...

Re: Kernel.bin not compiling correctly.

Post by UnsurpassedBlaze »

what is _alloca?

self made memory method ?

if yes ld can't find an reference to your function!
try to make an prototype like:

unsigned long _alloca(int pages); // Prototype

the same with _main ?

or you call an C-function from asm ?

then use in the asm file if you use nasm :

Extern _main
call _main
alloca is nowhere in my c++ methods and main is my initial c++ method:

Code: Select all

int main(void){ }
I'll try out the alloca thing tho.
Are you by chance using cygwin?

If so I had similar problems and ended up moving to a linux distro as the cygwin development tools seem to have some issuses. The issues were with ld mainly but the gcc flags also did not appear to take effect.

You need the following flags ( as posted earlier ) for gcc
-ffreestanding
-fno-builtin
-nostdlib
-nostartfiles

if you are using cygwin i would recommend trying some other dev tools or maybe a different version of cygwin.

dave
I'm not using cgywin, i'm using GCC. I tried those flags already and it still gives the same error. I just noticed that the extern error is also __main not _main so i'll try to find that file in either the asm or c++ file. If i still receive errors i'll post again.
The code is only as good as the programmer.
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Kernel.bin not compiling correctly.

Post by dave »

ok you did not understand me. Cygwin is a linux compatibilty layer so to speak for linux programs to run on windows. Are you using gcc on windows or linux?

Dave
User avatar
UnsurpassedBlaze
Posts: 10
Joined: Wed Nov 02, 2005 12:00 am
Location: Somewhere on Earth...

Re: Kernel.bin not compiling correctly.

Post by UnsurpassedBlaze »

gcc on windows
The code is only as good as the programmer.
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Kernel.bin not compiling correctly.

Post by dave »

ok then you must be using some kind of compatibilty layer either Cygwin or MinGW to allow gcc to run because as far as i know there is know native gcc for windows.

Hence my original response where gcc and ld under cygwin (or mingw) have issuses and do not seem to work properly. The problems I ran into were similar to the problems your having. I simply installed linuc in a virtual machine and used it to compile my stuff. If you don't want to do that then you may want to try a different compiler and linker.

Dave
User avatar
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Re: Kernel.bin not compiling correctly.

Post by deadmutex »

I had the same problem. I fixed it by changing
int main(void)
to
int _main(void)

and used __main in my asm code.
User avatar
UnsurpassedBlaze
Posts: 10
Joined: Wed Nov 02, 2005 12:00 am
Location: Somewhere on Earth...

Re: Kernel.bin not compiling correctly.

Post by UnsurpassedBlaze »

I think I now understand you dave. I had found GCC.exe in the bin folder of Dev-Cpp. I thought it might work since examples I found used GCC. So once I tried to put em together, one of the examples had compiled right while all the others hadn't. I have about 4 examples on making a kernel in C++ and only 1 had worked. The rest had given errors either about the startkernel.o is not recognized, file format not recognized or pe operations on a non-pe file(figured this out to be compile type). Then once I try to compile it after trying to fix errors I get that error about the _alloca and __main methods.

Anyways, after I fixed, I got an even new error:
ld: warning: cannot find entry symbol start; defaulting to 00100000
KernelStart.o(.text+0x1):kernelStart.asm: undefined reference to `_main'
Now this is a wierd error because I had defined this in the Kernel.cpp file:

Code: Select all

int _main(void)
The code is only as good as the programmer.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Kernel.bin not compiling correctly.

Post by earlz »

is that a prototype or your actual main
why in the crap does mingw have to have _main instead of main, that makes no sense to me
and on the version i am using the nostdlibs and nostartupcode seem to have no effect

isnt alloc used in normal c++ variables because it declares variables at runtime or am i wrong
User avatar
UnsurpassedBlaze
Posts: 10
Joined: Wed Nov 02, 2005 12:00 am
Location: Somewhere on Earth...

Re: Kernel.bin not compiling correctly.

Post by UnsurpassedBlaze »

Before in my c++ code i used the header

Code: Select all

int main(void)
and i got the __main and _alloca problems. Now i'm using

Code: Select all

int _main(void)
and i'm getting a _main problem o_O. And yes that is now my actual main. My old int main(void) code gave problems so i thought i might try that and it's still giving problems.
The code is only as good as the programmer.
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Kernel.bin not compiling correctly.

Post by dave »

if your referencing main from an assembly file that is compiled with nasm ( or possibly even another assembler) for some reason you need to remove the underscore from your assembly code. Do not remove the underscore from extern or global statements only from the actual assembly code. Not sure why this happens but it does.

Dave
robert macabre
Member
Member
Posts: 26
Joined: Fri Nov 18, 2005 12:00 am
Location: a perfect view out of the novotel

Re: Kernel.bin not compiling correctly.

Post by robert macabre »

the gcc compiler places an underscore in front of function and subroutine names. the assembler sees these names with the underscores out front, and that's what you've gotta use. for instance, to call

Code: Select all

int main() {}
you've got to use something like

Code: Select all

extern _main
call _main
[/quote]
Post Reply