title: Libraries compatibilty by cross-compiling node for armv5
body: <p>I try to cross-compile <a href="https://github.com/joyent/node" rel="nofollow">node</a> for my QNAP armv5te machine, on my Ubuntu 14.04 Desktop x64.</p>
  
  <p><em>A node QPKG exists in QNAP App-center, but its version is old (0.8.22).</em><br>
  Here are informations about the server :</p>
  
  <blockquote>
    <p>Linux SERVERNAME 3.4.6 #1 Mon Dec 29 06:00:47 CST 2014 armv5tel unknown<br>
    <strong>Processor name</strong>  : Feroceon 88F6281 rev 1 (v5l) @ 1.2 GHz<br>
    <strong>BogoMIPS</strong>        : 1196.85<br>
    <strong>Features</strong>        : swp half thumb fastmult edsp<br>
    <strong>CPU implementer</strong> : 0x56<br>
    <strong>CPU architecture</strong>: 5TE<br>
    <strong>CPU variant</strong>     : 0x2<br>
    <strong>CPU part</strong>        : 0x131<br>
    <strong>CPU revision</strong>    : 1<br>
    <strong>Hardware</strong>        : Feroceon-KW<br>
    <strong>ARM Revision</strong>    : 0000<br>
    <strong>Serial</strong>          : 0000000000000000</p>
  </blockquote>
  
  <p>Here's the command I used on my desktop :</p>
  
  <pre><code>apt-get update
  apt-get upgrade
  apt-get install emdebian-archive-keyring
  apt-get install libc6-armel-cross libc6-dev-armel-cross
  apt-get install binutils-arm-linux-gnueabi
  apt-get install gcc-4.7-arm-linux-gnueabi
  apt-get install g++-4.7-arm-linux-gnueabi
  apt-get install u-boot-tools
  apt-get install libncurses5-dev
  ln -s /user/bin/arm-linux-gnueabi-gcc-4.7 /usr/bin/arm-linux-gnueabi-gcc
  ln -s /user/bin/arm-linux-gnueabi-g++-4.7 /usr/bin/arm-linux-gnueabi-g++
  
  wget http://nodejs.org/dist/node-v0.10.35/node-v0.10.35.tar.gz
  tar -zxf node-v0.10.35.tar.gz
  cd node-v0.10.35
  
  export TOOL_PREFIX="arm-linux-gnueabi"
  export CC="${TOOL_PREFIX}-gcc"
  export CXX="${TOOL_PREFIX}-g++"
  export AR="${TOOL_PREFIX}-ar"
  export RANLIB="${TOOL_PREFIX}-ranlib"
  export LINK="${CXX}"
  export CCFLAGS="-march=armv5te -mfpu=softfp -marm"
  export CXXFLAGS="-march=armv5te -mno-unaligned-access"
  export OPENSSL_armcap=5
  export GYPFLAGS="-Darmeabi=soft -Dv8_can_use_vfp_instructions=false -Dv8_can_use_unaligned_accesses=false -Darmv7=0"
  export VFP3=off
  export VFP2=off
  
  ./configure --without-snapshot --dest-cpu=arm --dest-os=linux --prefix="/root/.nvm/v0.10.35"
  make -j 4
  make install
  tar -zcf node-v0.10.35-linux-armv5.tar.gz v0.10.35
  </code></pre>
  
  <p>The compilation doesn't show any failures with these parameters. So after that I send the tarball to my QNAP server:</p>
  
  <pre><code>scp /root/.nvm/node-v0.10.35-linux-armv5.tar.gz admin@SERVERNAME:/share/HDA_DATA/.qpkg/nodejs
  ssh SERVERNAME -l admin
  cd /share/HDA_DATA/.qpkg/nodejs
  tar -zxf node-v0.10.35-linux-armv5.tar.gz
  ln -s v0.10.35 node
  </code></pre>
  
  <p>All my env variables are already set on my server. Now I can test node binary...</p>
  
  <pre><code># node -v
  node: /usr/lib/libstdc++.so.6: version `CXXABI_ARM_1.3.3' not found (required by node)
  node: /lib/libc.so.6: version `GLIBC_2.15' not found (required by node)
  node: /lib/libc.so.6: version `GLIBC_2.11' not found (required by node)
  node: /lib/libc.so.6: version `GLIBC_2.7' not found (required by node)
  </code></pre>
  
  <p>Finally I have an error because C libraries are not the same on Ubuntu and Qnap, for Ubuntu desktop I have <code>ldd (Ubuntu EGLIBC 2.19-0ubuntu6.5) 2.19</code> and on QNAP <code>ldd (GNU libc) 2.5</code>.</p>
  
  <p><strong>libc-dev</strong> and <strong>libstdc++</strong> are packages handled by Optware ipkg on Qnap, (old versions too).</p>
  
  <p>My question is what is the better way to fix this problem ? Force updating libs on server ? (and how to do that ?) Or maybe use static libs during compilation ? ( and how to do that too ?) Or other options ?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After my conversation with artless-noise, I understood I had several ways to fix library dependencies...</p>
  
  <p>Dependencies in question:</p>
  
  <pre><code># ldd /opt/bin/node
  /opt/node/bin/node: /usr/lib/libstdc++.so.6: version `CXXABI_ARM_1.3.3' not found (required by /opt/node/bin/node)
  /opt/node/bin/node: /lib/libc.so.6: version `GLIBC_2.15' not found (required by /opt/node/bin/node)
  /opt/node/bin/node: /lib/libc.so.6: version `GLIBC_2.11' not found (required by /opt/node/bin/node)
  /opt/node/bin/node: /lib/libc.so.6: version `GLIBC_2.7' not found (required by /opt/node/bin/node)
          libdl.so.2 =&gt; /lib/libdl.so.2 (0xb6ed2000)
          librt.so.1 =&gt; /lib/librt.so.1 (0xb6ec3000)
          libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0xb6de2000)
          libm.so.6 =&gt; /lib/libm.so.6 (0xb6d32000)
          libgcc_s.so.1 =&gt; /lib/libgcc_s.so.1 (0xb6d1e000)
          libpthread.so.0 =&gt; /lib/libpthread.so.0 (0xb6cfe000)
          libc.so.6 =&gt; /lib/libc.so.6 (0xb6bca000)
          /lib/ld-linux.so.3 (0xb6ee4000)
  </code></pre>
  
  <ul>
  <li><p><strong>Copy libraries from Ubuntu GCC to the target machine, and override default ones :</strong><br>
  It could be really dangerous, and may brick the system. To more, my goal is to create a QPKG for QNAP community, so ask people to override their C libs is not a really nice method.</p></li>
  <li><p><strong>Copy libraries and cohabit with original ones :</strong><br>
  A nice method, just need to set <code>LD_LIBRARY_PATH</code> to a dir containing newest libs for the application. But I found an error using this method, again with c++ lib.</p></li>
  </ul>
  
  <p><strong>The error:</strong></p>
  
  <pre><code>node: symbol lookup error: /opt/node/lib/c/libstdc++.so.6: undefined symbol: _ZNSt11__timepunctIcE2idE, version GLIBCXX_3.4
  </code></pre>
  
  <ul>
  <li><strong>Create a static application :</strong><br>
  Finally, I found the way to do it without any errors during compilation, and during execution on the target machine. Just need to add some flags.</li>
  </ul>
  
  <p><strong>New flags:</strong></p>
  
  <pre><code>export CCFLAGS="-march=armv5te -mfpu=softfp -marm -static-libgcc"
  export CXXFLAGS="-march=armv5te -mno-unaligned-access -static-libstdc++"
  export LDFLAGS="-static"
  </code></pre>
  
  <p><strong>Checking dynamic library links:</strong></p>
  
  <pre><code># ldd /opt/bin/node
      not a dynamic executable
  # npm version
  { test: '1.0.0',
    npm: '2.3.0',
    ares: '1.9.0-DEV',
    http_parser: '1.0',
    modules: '11',
    node: '0.10.35',
    openssl: '1.0.1j',
    uv: '0.10.30',
    v8: '3.14.5.9',
    zlib: '1.2.8' }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong> Finally a problem is again here, most of the node functions work, but not <code>http</code>...</p>
  
  <p>i tested a simple script (from NodeJS API) to get info about a web page: </p>
  
  <pre><code>http.get("http://www.google.com/index.html", function(res) {
    console.log("Got response: " + res.statusCode);
  }).on('error', function(e) {
    console.log("Got error: " + e.message);
  });
  </code></pre>
  
  <p>And I got <code>Got error: getaddrinfo ENOTFOUND</code>, is it possible because node is static some features can't work ?</p>