gcc cross compiler problem

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
simmy

gcc cross compiler problem

Post by simmy »

sorry guys, im not too good at this cross compiler stuff.

ok so i did the first part of the gcc cross compiler tutoral, like the part until you get to troubleshooting and what not.

So i went back to the barebones turorial and i try the as -o loader.o loader.s thing and i get the same unrecognized character.

i dont really understand the usage part of the gcc cross compiler tutorial.

what am i missing???????

notes: i have cygwin with the full package.

thank you!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:gcc cross compiler problem

Post by Solar »

simmy wrote: So i went back to the barebones turorial and i try the as -o loader.o loader.s thing and i get the same unrecognized character.

i dont really understand the usage part of the gcc cross compiler tutorial.

what am i missing???????
You have to use your cross-compiler tools. ;) If you used /usr/cross as prefix, that means your cross-compiler tools are not in the search path for executables. 'as' is still the same 'as' that came with Cygwin, which doesn't know about ELF format.

The cross-compiler 'as' can be accessed as /usr/cross/bin/${TARGET}-as, or /usr/cross/${TARGET}/bin/as.

I would recommend you add /usr/cross/bin to your executable search path, by editing ~/.bash_profile :

Code: Select all

export PATH=$PATH:/usr/cross/bin
Then, follow the BareBones tutorial using ${TARGET}-as (e.g., i586-elf-as) instead of just 'as'.
Every good solution is obvious once you've found it.
simmy

Re:gcc cross compiler problem

Post by simmy »

so when i followed the tutorial i was suppose to fill in stuff like TARGET, PREFIX, and PATH with my own information i guess?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:gcc cross compiler problem

Post by Solar »

TARGET is the platform you want to target, e.g. i386-elf, i586-elf or the like.

PREFIX is where you want the stuff to be installed, like /usr/cross (recommended to keep things apart from the system toolchain).

The tutorial starts with the very two lines where you set these (Step 1 - Bootstrap, Preparation)...

Code: Select all

export PREFIX=/usr/cross
export TARGET=i586-elf
Later, prior to making the GCC, you extend the path:

Code: Select all

export PATH=$PATH:$PREFIX/bin
This is verbatim, i.e. you don't have to change anything. In fact, the only thing you have to change at all in the tutorial commands is exchanging [tt]binutils-x.xx[/tt] and [tt]gcc-x.x.x[/tt] with the actual versions you use (e.g., binutils-2.16.1 and gcc-4.0.2 or whatever).
Every good solution is obvious once you've found it.
aggieben

Re:gcc cross compiler problem

Post by aggieben »

I also have been having problems getting a working cross-tool chain.

First, I tried just using the cross-* setup that is now part of OpenBSD. Everything seemed to build fine, but when I went to create binaries, I always ended up with errors like "unresolved symbol __udivsi3" for symbols that *are* in libgcc (I verified with nm) but somehow not linked.

I compile like this:

gcc -c -o kernel.o -g -I../include kernel.c
ld -o kernel.img -lgcc -nostdlib kernel.o

I'm using -nostdlib, which would normally prevent the linking of libgcc, but when you explicitly link libgcc (with -lgcc), the symbols should be found ...but they're not.

I repeated the process by compiling all my cross tools from source (binutils and gcc) to make sure it wasn't just a problem with the OpenBSD cross-tool setup, but I got the same result. I'm building for arm-unknown-elf. I'm trying to build a kernel image to run directly on hardware (ok, ok, a QEMU Arm emulator).

Any help is appreciated.
froggey

Re:gcc cross compiler problem

Post by froggey »

Because of the way ld handles libraries, you need to put -lgcc last:
ld -o kernel.img -nostdlib kernel.o -lgcc
simmy

Re:gcc cross compiler problem

Post by simmy »

ok i get an Error 2 after i install the gcc tools.

during the binutils it says the gcc cross compiling is not working.

same thing during the gcc installation.

is there a way i can get a preconfigured cross compiler?!

i unpacked the .bz2 of both the gcc 4.1.1 and binutils 2.16.1 with 'tar -xjf' and then followed the tutorial.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:gcc cross compiler problem

Post by Solar »

I'd daresay some previous attempt at building a crosscompiler either screwed up your PATH, or your system compiler installation, or both, so that the binutils build procedure tries to run a non-functional system compiler.

Your best chance is probably to uninstall Cygwin, reinstall it (rather quickly done if you keep the downloaded packages intact), and try the tutorial again. It does work, I re-verified it with binutils-2.17 and GCC 4.1.1 just this morning.
Every good solution is obvious once you've found it.
simmy

Re:gcc cross compiler problem

Post by simmy »

how do i add /usr/src/cross to my PATH variable?

i can now show you the error i recieved after going to the end of step one of the gcc cross compiling tutorial:

http://216.39.201.3/members/images/error.PNG
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:gcc cross compiler problem

Post by Solar »

export PATH=$PATH:/usr/cross/bin

It's in the tutorial, actually... you might want to add this line to your ~/.profile so it gets executed when you log in...

Oh, and when you report a build error, always report the topmost error, not the last line printed. In your case, the "real" error was:

Code: Select all

make[2]: i586-elf-ar: Command not found
Every good solution is obvious once you've found it.
simmy

Re:gcc cross compiler problem

Post by simmy »

thanks for the advice

any suggestions on how to fix the error...?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:gcc cross compiler problem

Post by Solar »

By adding /usr/cross/bin to your path?
Every good solution is obvious once you've found it.
simmy

Re:gcc cross compiler problem

Post by simmy »

but i recieved this while i was installing gcc,not when trying to use it..
Post Reply