error while cross compiling

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
archanmehta
Posts: 3
Joined: Thu Feb 21, 2013 5:18 am

error while cross compiling

Post 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.
Attachments
Capture.PNG
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: error while cross compiling

Post 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.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
archanmehta
Posts: 3
Joined: Thu Feb 21, 2013 5:18 am

Re: error while cross compiling

Post 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. :)
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: error while cross compiling

Post by xenos »

Try -c option when compiling, you don't want to compile and link an executable, but just compile ;)
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: error while cross compiling

Post 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.
archanmehta
Posts: 3
Joined: Thu Feb 21, 2013 5:18 am

Re: error while cross compiling

Post by archanmehta »

Thank you XenOS and sortie. I am getting on to that.
Post Reply