others - 基于armv5的交叉编译node的库

我尝试在Ubuntu 14.04 Desktop x64上交叉编译node。

QNAP App-center中存在一个node QPKG,但其版本较旧(0.8.22)。
以下是有关服务器的信息:

Linux SERVERNAME 3.4.6 #1 Mon Dec 29 06:00:47 CST 2014 armv5tel unknown
处理器名称: Feroceon 88F6281 rev 1( v5l ) @1.2 GHz
BogoMIPS:1196.85
Features : swp half thumb fastmult edsp
CPU实现者:0x56
CPU架构:5TE
CPU版本:0x2
CPU部件:0x131
CPU版本:1
硬件:feroceon kw
ARM版本:0000
Serial : 0000000000000000

以下是我在桌面上使用的命令:


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

编译不会显示这些参数的故障,之后,我将tarball发送到QNAP服务器:


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

所有env变量已在服务器上设置,现在我可以测试node二进制文件。


# 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)

ldd (Ubuntu EGLIBC 2.19-0ubuntu6.5) 2.19在QNAP上ldd (GNU libc) 2.5

问题是什么更好的方法来修复这个问题?


相关项:


# 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 => /lib/libdl.so.2 (0xb6ed2000)
 librt.so.1 => /lib/librt.so.1 (0xb6ec3000)
 libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb6de2000)
 libm.so.6 => /lib/libm.so.6 (0xb6d32000)
 libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb6d1e000)
 libpthread.so.0 => /lib/libpthread.so.0 (0xb6cfe000)
 libc.so.6 => /lib/libc.so.6 (0xb6bca000)
 /lib/ld-linux.so.3 (0xb6ee4000)



错误:


node: symbol lookup error: /opt/node/lib/c/libstdc++.so.6: undefined symbol: _ZNSt11__timepunctIcE2idE, version GLIBCXX_3.4

  • 创建静态应用程序:
    最后,我找到了在编译期间,在目标机器上执行期间,没有错误的方法,只需要添加一些标志

新标志:


export CCFLAGS="-march=armv5te -mfpu=softfp -marm -static-libgcc"
export CXXFLAGS="-march=armv5te -mno-unaligned-access -static-libstdc++"
export LDFLAGS="-static"

检查动态库链接:


# 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' }


我测试了一个简单的脚本(来自NodeJS API )来获取关于网页的信息:


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);
});

我得到了Got error: getaddrinfo ENOTFOUND

时间:

我用了crosstools NG,但也可以使用官方的QNAP Maxwell-ARM Toolchain


gcc (GCC) 4.2.4
g++ (GCC) 4.2.4
GNU ld (crosstool-NG 1.20.0) 2.19.1
ldd (crosstool-NG) 1.20.0
Python 2.7.6 (with gyp)


cd /src
wget -q https://ftp.gnu.org/gnu/gcc/gcc-4.6.3/gcc-core-4.6.3.tar.gz
tar -zxf gcc-core-4.6.3.tar.gz
sed -i -e 's/define HIDDEN.*/define HIDDEN/' /src/gcc-4.6.3/gcc/config/arm/linux-atomic.c
export CC=arm-none-linux-gnueabi-gcc
export AR=arm-none-linux-gnueabi-ar
export RANLIB=arm-none-linux-gnueabi-ranlib
cd /src/gcc-4.6.3/gcc/config/arm
libtool --tag=CC --mode=compile $CC -g -O2 -MT linux-atomic.lo -MD -MP -MF linux-atomic.Tpo -c -o linux-atomic.lo linux-atomic.c
$AR cru /src/gcc-4.6.3/gcc/config/arm/.libs/liblinux-atomic.a /src/gcc-4.6.3/gcc/config/arm/.libs/linux-atomic.o
$RANLIB /src/gcc-4.6.3/gcc/config/arm/.libs/liblinux-atomic.a

# IMPORTANT: Assign environment variables like I made in my question above.

# Go to node src dir and configure
./configure --without-snapshot --dest-cpu=arm --dest-os=linux --prefix="${PREFIX_DIR}"

# When configuration is done, edit out/node.target.mk
vi out/node.target.mk

# Find LD_INPUTS files list and add your new library as last one:
# -> /src/gcc-4.6.3/gcc/config/arm/.libs/liblinux-atomic.a

# Now you can build node !
make -j4 #-jX where X is the number of available cores
make install DESTDIR=$TEMPDIR # Use DESTDIR to avoid installation directly in $PREFIX_DIR path

通过这种配置,我还可以使用GCC 4.1.3为x56处理器编译node,https://github.com/jbltx/nodejs-QPKG/tree/master/node-v0.10.35

...