ITK/Cross Compiling: Difference between revisions

From KitwarePublic
< ITK
Jump to navigationJump to search
No edit summary
No edit summary
Line 8: Line 8:
* Build System: The system where the executables are built.
* Build System: The system where the executables are built.


= In Linux for Mac =
= In Linux Host for Mac Target =
 
In this particular case we illustrate
 
* Target System = Mac
* Build System = Linux
 
== Major steps ==
 
# Build your tool chain in the build system
#* This is the set of compiler and linker that must be build in the '''build''' system, but will know how to generate code for the Target system.
# Create a TryRun ... file in the '''native''' system
#* This could be generated (as a skeleton) with the following commands
 
=== Building the ToolChain ===
 
The following is a script developed by Johannes Schindelin (originally intended for [http://pacific.mpi-cbg.de/wiki/index.php/Fiji FIJI])
 
[[Media:Build-macosx-cross-compiler.sh.gz|Script for Building the Darwing Toolchain in Linux]]
 
Following the advice of the CMake Wiki [http://www.cmake.org/Wiki/CMake_Cross_Compiling]
 
Put the following in a file called ToolChain.cmake
 
  # this one is important
  SET(CMAKE_SYSTEM_NAME Linux)
  #this one not so much
  SET(CMAKE_SYSTEM_VERSION 1)
  # specify the cross compiler
  SET(CMAKE_C_COMPILER  /usr/bin/gcc)
  SET(CMAKE_CXX_COMPILER /usr/bin/g++)
  # where is the target environment
  SET(CMAKE_FIND_ROOT_PATH  /usr)
  # search for programs in the build host directories
  SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  # for libraries and headers in the target directories
  SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
 
and run it with CMake using the command (in an empty directory)
 
  cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake  ~/src/ITK
 
This will generate (among many other things) a File called
 
              TryRunResults.cmake
 
Then, manually populate, the values of each one of the fields.
 
# Copy the file to the build system
#* Do the command in the build system.
 
    cmake -C ~/TryRunResults.cmake  .
 
 
 
= In Linux Host for Windows Target =


In this particular case we illustrate
In this particular case we illustrate

Revision as of 21:13, 11 February 2011

This page describes the procedure to follow when cross compiling for another system.

In this page, we will refer to the system as:

  • Target System: The system where the executables are intended to run.
  • Build System: The system where the executables are built.

In Linux Host for Mac Target

In this particular case we illustrate

  • Target System = Mac
  • Build System = Linux

Major steps

  1. Build your tool chain in the build system
    • This is the set of compiler and linker that must be build in the build system, but will know how to generate code for the Target system.
  2. Create a TryRun ... file in the native system
    • This could be generated (as a skeleton) with the following commands

Building the ToolChain

The following is a script developed by Johannes Schindelin (originally intended for FIJI)

Script for Building the Darwing Toolchain in Linux

Following the advice of the CMake Wiki [1]

Put the following in a file called ToolChain.cmake

 # this one is important
 SET(CMAKE_SYSTEM_NAME Linux)
 #this one not so much
 SET(CMAKE_SYSTEM_VERSION 1)
 # specify the cross compiler
 SET(CMAKE_C_COMPILER   /usr/bin/gcc)
 SET(CMAKE_CXX_COMPILER /usr/bin/g++)
 # where is the target environment
 SET(CMAKE_FIND_ROOT_PATH  /usr)
 # search for programs in the build host directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 # for libraries and headers in the target directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

and run it with CMake using the command (in an empty directory)

 cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake   ~/src/ITK

This will generate (among many other things) a File called

              TryRunResults.cmake

Then, manually populate, the values of each one of the fields.

  1. Copy the file to the build system
    • Do the command in the build system.
   cmake -C ~/TryRunResults.cmake  .


In Linux Host for Windows Target

In this particular case we illustrate

  • Target System = Mac
  • Build System = Linux

Major steps

  1. Build your tool chain in the build system
    • This is the set of compiler and linker that must be build in the build system, but will know how to generate code for the Target system.
  2. Create a TryRun ... file in the native system
    • This could be generated (as a skeleton) with the following commands

Building the ToolChain

The following is a script developed by Johannes Schindelin (originally intended for FIJI)

Script for Building the Darwing Toolchain in Linux

Following the advice of the CMake Wiki [2]

Put the following in a file called ToolChain.cmake

 # this one is important
 SET(CMAKE_SYSTEM_NAME Linux)
 #this one not so much
 SET(CMAKE_SYSTEM_VERSION 1)
 # specify the cross compiler
 SET(CMAKE_C_COMPILER   /usr/bin/gcc)
 SET(CMAKE_CXX_COMPILER /usr/bin/g++)
 # where is the target environment
 SET(CMAKE_FIND_ROOT_PATH  /usr)
 # search for programs in the build host directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 # for libraries and headers in the target directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

and run it with CMake using the command (in an empty directory)

 cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake   ~/src/ITK

This will generate (among many other things) a File called

              TryRunResults.cmake

Then, manually populate, the values of each one of the fields.

  1. Copy the file to the build system
    • Do the command in the build system.
   cmake -C ~/TryRunResults.cmake  .