views:

57

answers:

1
+1  Q: 

cross compilers

I've seen the about cross compilers reply at http://stackoverflow.com/questions/579695/how-do-i-cross-compile-c-code-on-windows-for-a-binary-to-also-be-run-on-unix-sol

and i would like to know how can i compile for sparc on x86 machine? where can i find a good cross compiler? I also need for HP OS .

if you link me to a good step by step tutorial It will be the best

Thanks. Elad.

+3  A: 

gcc is fully capable of this. Sun's compiler may be capable, but I'm more familiar with gcc. First, you should get comfortable with building gcc, and also decide if you need just the C compiler or if you need C++ or other languages.

Once you've built gcc for the host you are on, you can then rebuild gcc to include a target for the target machine you want to cross compile for.

When building a cross compiler, the three things you must get correct are the build, host, and target.

  • build: the machine you are building on
  • host: the machine that you are building for
  • target: and the machine that GCC will produce code for

For a cross compiler, build and host will be the same, and target will be different. For example, here's how to tell the compiler to build a compiler to cross compile from Solaris x86 to Solaris Sparc:

./configure --build=x86_64-sun-solaris2.10 --host=x86_64-sun-solaris2.10 --target=sparc-sun-solaris2.10

You can then build additional compiler for each target you need to cross compile to.

Compiling 32 bit and 64 bit executables on a platform which runs both is quite easy. Anything else, will be a bit trickier. gcc on the Mac is built with several targets, and Apple has made it quite easy to create binaries for multiple platforms. All iPhone apps are compiled on x86 and target the ARM processor. If you can get the compiler built for the targets you want, then the cross compiling is usually fairly easy to do.

brianegge