Kernel.bin not compiling correctly.
- UnsurpassedBlaze
- Posts: 10
- Joined: Wed Nov 02, 2005 12:00 am
- Location: Somewhere on Earth...
Kernel.bin not compiling correctly.
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).
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).
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: Kernel.bin not compiling correctly.
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
Assuming you're using gcc, you'll want to compile with the following options enabled:
-ffreestanding
-fno-builtin
-nostdlib
-nostartfiles
Cheers,
Jeff
- UnsurpassedBlaze
- Posts: 10
- Joined: Wed Nov 02, 2005 12:00 am
- Location: Somewhere on Earth...
Re: Kernel.bin not compiling correctly.
Now there's warnings coming from the bat file I made. Here's the complete output:
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: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 . . .
Yet I have NO kind of call to those methods.[/code]kernel_c.o(.text+0x54):kernel_c.cpp: undefined reference to `_alloca'
kernel_c.o(.text+0x59):kernel_c.cpp: undefined reference to `__main'
-
- Member
- Posts: 132
- Joined: Wed Nov 03, 2004 12:00 am
- Location: Austria
- Contact:
Re: Kernel.bin not compiling correctly.
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
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
Re: Kernel.bin not compiling correctly.
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
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
- UnsurpassedBlaze
- Posts: 10
- Joined: Wed Nov 02, 2005 12:00 am
- Location: Somewhere on Earth...
Re: Kernel.bin not compiling correctly.
alloca is nowhere in my c++ methods and main is my initial c++ method: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
Code: Select all
int main(void){ }
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.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
The code is only as good as the programmer.
Re: Kernel.bin not compiling correctly.
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
Dave
- UnsurpassedBlaze
- Posts: 10
- Joined: Wed Nov 02, 2005 12:00 am
- Location: Somewhere on Earth...
Re: Kernel.bin not compiling correctly.
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
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
Re: Kernel.bin not compiling correctly.
I had the same problem. I fixed it by changing
int main(void)
to
int _main(void)
and used __main in my asm code.
int main(void)
to
int _main(void)
and used __main in my asm code.
- UnsurpassedBlaze
- Posts: 10
- Joined: Wed Nov 02, 2005 12:00 am
- Location: Somewhere on Earth...
Re: Kernel.bin not compiling correctly.
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:
Anyways, after I fixed, I got an even new error:
Now this is a wierd error because I had defined this in the Kernel.cpp file:ld: warning: cannot find entry symbol start; defaulting to 00100000
KernelStart.o(.text+0x1):kernelStart.asm: undefined reference to `_main'
Code: Select all
int _main(void)
The code is only as good as the programmer.
Re: Kernel.bin not compiling correctly.
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
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
- UnsurpassedBlaze
- Posts: 10
- Joined: Wed Nov 02, 2005 12:00 am
- Location: Somewhere on Earth...
Re: Kernel.bin not compiling correctly.
Before in my c++ code i used the header and i got the __main and _alloca problems. Now i'm using 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.
Code: Select all
int main(void)
Code: Select all
int _main(void)
The code is only as good as the programmer.
Re: Kernel.bin not compiling correctly.
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
Dave
-
- 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.
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
you've got to use something like
[/quote]
Code: Select all
int main() {}
Code: Select all
extern _main
call _main