title: How to cross compile CMake for ARM with CMake
body: <p>In short I'm trying to cross compile CMake with CMake, and I don't think I'm linking libraries correctly. What I want to do may not be possible, but I'd at least like to know why it isn't possible if that's the case.</p>
  
  <p>System: The host is a <a href="http://wiki.embeddedarm.com/wiki/TS-7520-BOX" rel="noreferrer">Linux box</a> with a Cavium ARM9 CPU. It's currently running version 2.6.24.4 of the Linux kernel and <a href="https://en.wikipedia.org/wiki/Debian_version_history#Debian_5.0_(Lenny)" rel="noreferrer">Debian&nbsp;5.0</a> (Lenny). My workstation is a <a href="https://en.wikipedia.org/wiki/Intel_Core#Core_i5" rel="noreferrer">Core&nbsp;i5</a> running Ubuntu&nbsp;12.04 LTS (Precise Pangolin).</p>
  
  <p>My overall goal is to get <a href="http://www.ros.org/wiki/fuerte/Installation/Debian" rel="noreferrer">ROS</a> running on the Linux box. I have to compile from source rather than use apt since Debian&nbsp;6.0 (Squeeze) binaries require thumb support that the Cavium does not give, and not many of the needed packages are available for Debian&nbsp;5.0 (Lenny). I'd made progress installing the various libraries needed, but when I got to step 1.3.1 and tried to run CMake, I got the error</p>
  
  <blockquote>
    <p>CMake 2.8 or higher is required. You are running version 2.6.0</p>
  </blockquote>
  
  <p>Next I tried to download and build CMake 2.8.8 on the Linux box itself, but it was too much for the system. When that failed, I downloaded the toolchain suggested on the manufacturer's website and used the cross-compiling guide at [www.cmake.org/Wiki/CMake_Cross_Compiling] to build the CMake executables. Here is my toolchain file:</p>
  
  <pre><code># This one is important
  SET(CMAKE_SYSTEM_NAME Linux)
  
  # Specify the cross compiler
  SET(CMAKE_C_COMPILER   /pathto/crosstool-linux-gcc-4.5.2-gclibc-2.9-oabi/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-gcc)
  SET(CMAKE_CXX_COMPILER /pathto/crosstool-linux-gcc-4.5.2-gclibc-2.9-oabi/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-g++)
  
  # Where is the target environment
  SET(CMAKE_FIND_ROOT_PATH  /pathto/crosstool-linux-gcc-4.5.2-gclibc-2.9-oabi/arm-unknown-linux-gnu /pathto/crosstool-linux-gcc-4.5.2-gclibc-2.9-oabi/arm-unknown-linux-gnu/arm-unknown-linux-gnu)
  
  # 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)
  </code></pre>
  
  <p>However, use of the binary on the Linux box gives the error</p>
  
  <blockquote>
    <p>cmake: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by cmake)</p>
  </blockquote>
  
  <p>Sure enough, the library is not there:</p>
  
  <pre><code>prompt# strings /usr/lib/libstdc++.so.6 | grep GLIBC
  GLIBCXX_3.4
  GLIBCXX_3.4.1
  GLIBCXX_3.4.2
  GLIBCXX_3.4.3
  GLIBCXX_3.4.4
  GLIBCXX_3.4.5
  GLIBCXX_3.4.6
  GLIBCXX_3.4.7
  GLIBCXX_3.4.8
  GLIBCXX_3.4.9
  GLIBCXX_3.4.10
  GLIBC_2.3
  GLIBC_2.0
  GLIBC_2.3.2
  GLIBC_2.1
  GLIBC_2.1.3
  GLIBC_2.2
  GLIBCXX_FORCE_NEW
  GLIBCXX_DEBUG_MESSAGE_LENGTH
  </code></pre>
  
  <p>I've never cross-compiled before, but I can see one of two scenarios happening: either the binary got created with a link to a higher version of glibcxx on the host machine or the manufacturer's toolchain is more modern than their image. I don't know how to check which is happening or if something else is happening that I don't know about.</p>
  
  <p>My last effort involved trying to statically cross-compile CMake to hopefully get rid of the linking error with</p>
  
  <pre><code>cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-technologic.cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-static" ..
  </code></pre>
  
  <p>I got build errors, and that binary didn't work either. I got:</p>
  
  <pre><code>FATAL: kernel too old
  Segmentation fault
  </code></pre>
  
  <p>I'd try installing glibcxx 3.4.14 on the Linux box, but it doesn't look like it's available for this processor.</p>
  
  <p>I've tried searching for CMake dependencies or system requirements and can't find anything. I've also searched on how to build CMake, but most searches turn up how to build other things <em>with</em> CMake rather than building CMake itself.</p>