Page 1 of 1
error while cross compiling
Posted: Thu Feb 21, 2013 5:37 am
by archanmehta
I am developing an OS right from scratch.
Till now i am able to jump to protected mode (code written in assembly) as in protected mode i will be able to program using C language so i intended on developing cross compiler.
For that I used the guide on wiki.osdev.org/GCC_Cross-Compiler. I have got the exe file for compiling my OS file but i keep on getting an error message, image is posted below. 'test.c' file contains "void main(){}" and nothing else.
Any help regarding it would be use full.
EDIT: I am using windows as development platform.
Re: error while cross compiling
Posted: Thu Feb 21, 2013 5:45 am
by Griwes
1) void main () {} is not a valid hosted application (try compiling it with proper options, i.e. -std=c99).
2) Why are you trying to build hosted application using cross compiler?
I guess you need to read wiki more carefully.
Re: error while cross compiling
Posted: Thu Feb 21, 2013 5:56 am
by archanmehta
I want to check whether i am able to cross compile successfully for that purpose i am compiling a c program with nothing in it. I am not going to make any application.
Sorry my bad, i forgot to tell compiler not to link.
Thanks for help.
Re: error while cross compiling
Posted: Thu Feb 21, 2013 10:07 am
by xenos
Try -c option when compiling, you don't want to compile and link an executable, but just compile
Re: error while cross compiling
Posted: Fri Feb 22, 2013 6:38 am
by sortie
You are attempting to compile a hosted program using the i585-elf-gcc compiler. A hosted program needs a C standard library in order to function. For instance, the main function is not the actual program entry point. Rather, the program begins execution at _start (but that depends on the platform, you can do something else if you set up an OS-specific toolchain). This _start function is normally in crt0.o, which is often written in assembly and does something like: "initialize_standard_library(argc, argv); call_global_constructors(); exit(main(argc, argv));" (or what your standard library needs done). It sounds like you don't have an user-space yet, and hence probably not a C library. Compiling a hosted program, therefore, will not work because it needs a C standard library. If you get a running user-space, you can create a C library and point gcc (during configure) to your system root and headers. It will then know how to use your libc (creating an OS-specific toolchain is recommended). But that is all stuff you'll have to deal with in the future.
Right now, you are entering protected mode and you wish to, perhaps, cross-compile a kernel? In that case, you'll need to provide at least -ffreestanding to your kernel to compile a freestanding program (as opposed to a hosted program, that have all the user-space things available such as a C library). Read the wiki tutorials on how to write a kernel using a cross-compiler.
Re: error while cross compiling
Posted: Tue Feb 26, 2013 7:52 am
by archanmehta
Thank you XenOS and sortie. I am getting on to that.