Michael Torrie's Personal Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

computer_stuff:crosscompiler [2010/04/29 17:21]
Michael Torrie
computer_stuff:crosscompiler [2010/04/29 17:38] (current)
Michael Torrie
Line 1: Line 1:
 ====== Cross Compiling With GCC ====== ====== Cross Compiling With GCC ======
 +**Important note** - Although this document was originally written in 2004, and refers to version of gcc, binutils, glibc, and mingw runtimes that are now obsolete, the basic procedures for setting up a cross-compiling environment from scratch are still the same today. ​ For Linux users, most modern distros including Fedora and Ubuntu actually have official packages for installing a cross-compiling environment that targets MS Windows. ​ Rather than building your own compiler, you are advised to use the officially provided ones if you happen to need to build MS Windows executables on Linux.
 +
 The GNU Compiler Collection lends itself extremely well to cross compiling, due to its modular architecture. This page is a brief overview of setting up GCC to compile executables to run on foreign linux platforms, and also the Mingw Win32 platform The GNU Compiler Collection lends itself extremely well to cross compiling, due to its modular architecture. This page is a brief overview of setting up GCC to compile executables to run on foreign linux platforms, and also the Mingw Win32 platform
 What is Cross Compiling What is Cross Compiling
Line 18: Line 20:
  
 ^ Switch ^ Explaination ^ ^ Switch ^ Explaination ^
-| --build | The architecture of the host OS (usually autodetected) | +%%--%%build | The architecture of the host OS (usually autodetected) | 
-| --host | The architecture of the OS that the resulting program will run on | +%%--%%host | The architecture of the OS that the resulting program will run on | 
-| --target | The architecture of the OS that this program is intended to work with |+%%--%%target | The architecture of the OS that this program is intended to work with |
  
-Note the subtle difference between the ''​--host''​ and ''​--target''​ flags. When building a cross compiler, both bintuils and gcc are configured with the ''​--target''​ set to the target operating system, but since they are cross compilers, they will run on the local host OS. Thus we don't specify anything for the ''​--host''​ option. For building libraries and binaries with our cross compiler, we would specify both the ''​--target''​ and ''​--host''​ flags to be the target operating system because the libraries or binaries are intended to actually run on that platform.+Note the subtle difference between the ''​%%--%%host''​ and ''​%%--%%target''​ flags. When building a cross compiler, both bintuils and gcc are configured with the ''​%%--%%target''​ set to the target operating system, but since they are cross compilers, they will run on the local host OS. Thus we don't specify anything for the ''​%%--%%host''​ option. For building libraries and binaries with our cross compiler, we would specify both the ''​%%--%%target''​ and ''​%%--%%host''​ flags to be the target operating system because the libraries or binaries are intended to actually run on that platform.
  
 The architecture designations used by autoconf configure scripts usually are in the following format: The architecture designations used by autoconf configure scripts usually are in the following format:
Line 57: Line 59:
  
 ==== Configuring and compiling bintuils ==== ==== Configuring and compiling bintuils ====
-After unpacking and patching binutils, run configure in the root of the source tree with the ''​--target''​ set to ''​i386-redhat-linux'':​+After unpacking and patching binutils, run configure in the root of the source tree with the ''​%%--%%target''​ set to ''​i386-redhat-linux'':​
 <​code>​ <​code>​
 ./configure --prefix=/​sw --target=i386-redhat-linux ./configure --prefix=/​sw --target=i386-redhat-linux
Line 120: Line 122:
 </​code>​ </​code>​
  
-Although most native gcc distributions will compile will all possible languages enabled, most often you only want C, C++ and possibly objc or java. Use the --enable-languages switch to specify the languages you want the cross compiler to support. Except for the --prefix switch, you can pass all the flags to configure that the native compiler used. Just add the appropriate ''​--target''​ switch.+Although most native gcc distributions will compile will all possible languages enabled, most often you only want C, C++ and possibly objc or java. Use the %%--%%enable-languages switch to specify the languages you want the cross compiler to support. Except for the %%--%%prefix switch, you can pass all the flags to configure that the native compiler used. Just add the appropriate ''​%%--%%target''​ switch.
  
 A working example of configuration is the following: A working example of configuration is the following:
Line 139: Line 141:
  
 ==== Cross-compiling Autoconf-enabled Packages ==== ==== Cross-compiling Autoconf-enabled Packages ====
-To compile an autoconf configured program to run on a target architecture using your cross compiler, and if the configure.in file supports it, you configure using the --target and --host switches together: +To compile an autoconf configured program to run on a target architecture using your cross compiler, and if the configure.in file supports it, you configure using the %%--%%target and %%--%%host switches together: 
- +<​code>​ 
-    ./configure --target=i386-redhat-linux --host=i386-redhat-linux+./configure --target=i386-redhat-linux --host=i386-redhat-linux 
 +</​code>​
  
 ===== Building an i386-pc-mingw32 Cross Compiler ===== ===== Building an i386-pc-mingw32 Cross Compiler =====
Line 225: Line 228:
 </​code>​ </​code>​
  
-==== Adding Libraries To the Cross Compiling Environment ====+===== Adding Libraries To the Cross Compiling Environment ====
 ==== Linux Targets ==== ==== Linux Targets ====
  
Line 237: Line 241:
  
 ===== Links ===== ===== Links =====
-  * http://www.wxwindows.org/technote/​crosscmp.htm ​- notes on setting up a cross compiler targetting mingw32 on linux and using the wxWindows library in that environment+  * http://wiki.wxwidgets.org/Cross-Compiling_Under_Linux ​- notes on setting up a cross compiler targetting mingw32 on linux and using the wxWindows library in that environment
   * http://​www.mingw.org - Official site for the Mingw32 tools for Windows.   * http://​www.mingw.org - Official site for the Mingw32 tools for Windows.
   * http://​sources.redhat.com/​autobook/​autobook/​autobook_262.html#​SEC262 - Autoconf documentation on building a cross compiler   * http://​sources.redhat.com/​autobook/​autobook/​autobook_262.html#​SEC262 - Autoconf documentation on building a cross compiler
   * http://​bytesex.org/​cross-compiler.html - a good mini-howto on building cross compilers. Also has some good tips for extracting the source tarballs and patches from RedHat SRPMS.   * http://​bytesex.org/​cross-compiler.html - a good mini-howto on building cross compilers. Also has some good tips for extracting the source tarballs and patches from RedHat SRPMS.
-  * http://​linuxdevices.com/​articles/​AT6830035793.html - Detailed how-to: Cross-compiling for Sharp Zaurus 
- 

QR Code
QR Code computer_stuff:crosscompiler (generated for current page)