GCC Cross-compiler

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
User avatar
Tomaka17
Member
Member
Posts: 67
Joined: Thu Oct 02, 2008 8:20 am

GCC Cross-compiler

Post by Tomaka17 »

Hello,

In page http://wiki.osdev.org/GCC_Cross-Compiler
You can add a 'Yes' to GCC 4.4.0 with binutils 2.17


I also wanted to ask: when building binutils, gcc and newlib... why not remove the --prefix=$PREFIX things?
If you don't precise any prefix the compiler will automatically be installed in /usr/local, which is already in $PATH

Binaries, include files, etc. won't conflict with each other (if building multiple cross compilers) or with an existing gcc because they are installed in /usr/local/(target)/, /usr/local/bin/(target)-gcc/, /usr/local/lib/gcc/(target)/, etc.

I think it would be much simplier to do so, and I think that's the way it should be normally done
MysteriOS
Currently working on: TCP/IP
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: GCC Cross-compiler

Post by pcmattman »

The prefix is useful in certain situations.

In my case, I have cross-compilers which require support libraries & headers (that I provide), and without the PREFIX it'd be difficult to do that.

If you're just looking for a stock cross-compiler, you don't need the prefix (but it is nice, as you can delete the one directory if you want to remove the compiler rather than navigating a tree of folders).
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: GCC Cross-compiler

Post by Solar »

I admit that, originally, I was afraid to go with the default, as it was very poorly documented just what that default would be - I was unwilling to jeopardize my installation.

And after that, I left the --prefix in the tutorial, because it gives a hint what could be done if you aren't root on the machine, is explicit (I always prefer explicitness over implicit functionality), and is easy to delete-and-redo.
Every good solution is obvious once you've found it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: GCC Cross-compiler

Post by AJ »

Oooh - I missed the release of 4.4! [rebuilds cross compiler]

And another "vote" here for leaving --prefix in for the ease of deletion and rebuilding.

Cheers,
Adam
User avatar
Tomaka17
Member
Member
Posts: 67
Joined: Thu Oct 02, 2008 8:20 am

Re: GCC Cross-compiler

Post by Tomaka17 »

I understand the "ease of deletion" argument (thought I don't know why you would delete it :o )

But like Solar the first time I wanted to create a cross-compiler I thought that without that --prefix argument my newly-compiled GCC would overwrite the one already installed
That seems ridiculous but I was so afraid of this that I was checking several times if I had spelled '--prefix' correctly :P

Why not a single paragraph saying "The --prefix parameter is optional but we recommand using it" ?
MysteriOS
Currently working on: TCP/IP
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GCC Cross-compiler

Post by Combuster »

I don't know why you would delete it
To replace it with a newer version? Update cygwin? :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: GCC Cross-compiler

Post by Firestryke31 »

Or if you realize you misconfigured it.

"D'oh! I forgot to add that one flag that does the thing to the stuff so I can do this to that! Well, there goes 7 hours of work."
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

Re: GCC Cross-compiler

Post by kubeos »

I was wondering why no one has posted a tutorial yet for a native build of gcc and binutils.. It's remarkably easy as
long as you have a good libgloss with your newlib. I think I had to add about 15 new functions to my libgloss to get a
native compiler. And the configure command is pretty straight forward too -> I had to do a bit of research on the net to find out --host was not the computer you were building everything on.

Hope the info below helps someone. I had problems with the gcc that came default with cygwin, so I built a new version for it before I did a native build for my OS.

$BUILD refers to the machine you are currently compiling on.
For binutils:
../binutils-x-x-x/configure --prefix=$PREFIX --target=$TARGET --host=$TARGET --build=$BUILD --disable-nls

For gcc:
../gcc-x-x-x/configure --prefix=$PREFIX --target=$TARGET --host=$TARGET --build=$BUILD --disable-nls --enable-languages=c


While building, binutils and gcc would error out with undefined references. I just added these to my libgloss till it finally finished and installed. Voila, native toolchain

Pretty straight forward, but I'm not volunteering to make a tutorial. Maybe someone could fix this up(and any mistakes) and post it on the wiki. But hopefully this post will help someone out who doesn't know what to do about a native toolchain.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: GCC Cross-compiler

Post by Solar »

kubeos wrote:I was wondering why no one has posted a tutorial yet for a native build of gcc and binutils.. It's remarkably easy as long as you have a good libgloss with your newlib.
Well yes... if you go for Newlib. Porting Newlib would be the Step 2 mentioned in the GCC Cross-Compiler tutorial. Then would come Step 3 (complete cross-compiler), then would come Step 4 (native build).

Adding a C library is a point at which the tutorial "forks". Newlib is probably the "easiest" way to go currently, but some might not agree with Newlib because of its licensing, or its OS interface, or its scope, or whatever, and might want to use a different C library...
Every good solution is obvious once you've found it.
Post Reply