tags:

views:

118

answers:

4

Are there c++ compilers that I can run on a brand x system that will create machine code that will run on a brand y system? Would this be considered a cross compiler?

+1  A: 

Yes this is what cross-compilation is about (although I would say "brand X" isn't appropriate classification term).

jldupont
Doesn't have to be CPU type - it can be same arch but different runtime. Prime example is Linux x86 cross compiler to Windows x86.
LiraNuna
+10  A: 

Yes, that's exactly what a cross compiler is.

The GNU Compiler Collection (which includes gcc and g++) are a prime example of a portable cross compiler with hundreds of supported CPU types.

There are many ways to configure GCC to be a cross compiler. Most of it depends on the target machine and what's available from it - mostly because of the C runtime environment. For example, compiling GCC for an ARM Linux target requires an ARM Linux glibc pre-compiled to build the cross compiler libstdc++.

LiraNuna
+1  A: 

Yes there are such compilers; yes, they are called cross compilers. For example, GCC can be configured in this manner, so that I can run the compiler on a 32-bit x86 system, but produce 64-bit code for an x64 system, and that's just the tip of the iceberg.

Crosstool is a really handy tool suite for creating a cross-compiling GCC.

HTH,

Eric Melski

Electric Cloud, Inc.

Eric Melski
+2  A: 

This is quite common using gcc.

There are a number of tutorials around that describe building your own cross-compiler environment. This is one, but a quick google will probably provide a link to someone doing exactly the mix of environments that you're after.

edit: This is a more thorough tutorial, using crosstool

Andrew Edgecombe
There's also this tutorial: http://wiki.osdev.org/GCC_Cross-Compiler, which can be used on Windows with Cygwin/MinGW as well as on Linux.
Matthew Iselin