armv5 交叉编译节点的库兼容性 [英] Libraries compatibilty by cross-compiling node for armv5

查看:67
本文介绍了armv5 交叉编译节点的库兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的 Ubuntu 14.04 桌面 x64 上为我的 QNAP armv5te 机器交叉编译 node.

I try to cross-compile node for my QNAP armv5te machine, on my Ubuntu 14.04 Desktop x64.

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

A node QPKG exists in QNAP App-center, but its version is old (0.8.22).
Here are informations about the server :

Linux SERVERNAME 3.4.6 #1 Mon Dec 29 06:00:47 CST 2014 armv5tel 未知
处理器名称:Feroceon 88F6281 rev 1 (v5l) @ 1.2 GHz
BogoMIPS:1196.85
特点:swp半拇指fastmult edsp
CPU 实施者:0x56
CPU 架构:5TE
CPU 变体:0x2
CPU 部分:0x131
CPU 修订版:1
硬件:Feroceon-KW
ARM 修订版:0000
序列:0000000000000000

Linux SERVERNAME 3.4.6 #1 Mon Dec 29 06:00:47 CST 2014 armv5tel unknown
Processor name : Feroceon 88F6281 rev 1 (v5l) @ 1.2 GHz
BogoMIPS : 1196.85
Features : swp half thumb fastmult edsp
CPU implementer : 0x56
CPU architecture: 5TE
CPU variant : 0x2
CPU part : 0x131
CPU revision : 1
Hardware : Feroceon-KW
ARM Revision : 0000
Serial : 0000000000000000

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

Here's the command I used on my desktop :

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 服务器:

The compilation doesn't show any failures with these parameters. So after that I send the tarball to my QNAP server:

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

我所有的环境变量都已经在我的服务器上设置了.现在我可以测试节点二进制文件...

All my env variables are already set on my server. Now I can test node binary...

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

最后我有一个错误,因为 Ubuntu 和 Qnap 上的 C 库不一样,对于 Ubuntu 桌面我有 ldd (Ubuntu EGLIBC 2.19-0ubuntu6.5) 2.19 和 QNAP ldd(GNU libc) 2.5.

Finally I have an error because C libraries are not the same on Ubuntu and Qnap, for Ubuntu desktop I have ldd (Ubuntu EGLIBC 2.19-0ubuntu6.5) 2.19 and on QNAP ldd (GNU libc) 2.5.

libc-devlibstdc++ 是由 Optware ipkg 在 Qnap 上处理的包,(旧版本也是如此).

libc-dev and libstdc++ are packages handled by Optware ipkg on Qnap, (old versions too).

我的问题是解决这个问题的更好方法是什么?强制更新服务器上的库?(以及如何做到这一点?)或者在编译期间使用静态库?(以及如何做到这一点?)或其他选择?

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 ?

在与 artless-noise 交谈后,我了解到我有几种方法可以修复库依赖项...

After my conversation with artless-noise, I understood I had several ways to fix library dependencies...

有问题的依赖关系:

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

  • 将库从 Ubuntu GCC 复制到目标机器,并覆盖默认库:
    这可能真的很危险,并且可能会破坏系统.更重要的是,我的目标是为 QNAP 社区创建一个 QPKG,所以要求人们覆盖他们的 C 库并不是一个很好的方法.

    • Copy libraries from Ubuntu GCC to the target machine, and override default ones :
      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.

      复制图书馆并与原始图书馆同居:
      一个不错的方法,只需要将 LD_LIBRARY_PATH 设置为包含应用程序最新库的目录.但是我用这个方法发现了一个错误,再次使用c++ lib.

      Copy libraries and cohabit with original ones :
      A nice method, just need to set LD_LIBRARY_PATH to a dir containing newest libs for the application. But I found an error using this method, again with c++ lib.

      错误:

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

        <小时>

        最后一个问题又来了,大多数节点功能都可以工作,但http...


        Finally a problem is again here, most of the node functions work, but not http...

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

        i tested a simple script (from NodeJS API) to get info about a web page:

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

        而且我收到了出现错误:getaddrinfo ENOTFOUND,这可能是因为节点是静态的,某些功能无法工作吗?

        And I got Got error: getaddrinfo ENOTFOUND, is it possible because node is static some features can't work ?

        推荐答案

        最后,我没有尝试更改库,而是决定拥有一个与我的目标完美匹配的更好的交叉编译器.

        Finally, instead of trying to change libraries, I decided to have a better cross-compiler which matches with my target perfectly.

        为此我使用了 Crosstools-NG,但我可以使用官方的QNAP Maxwell-ARM 工具链也是(我看的太晚了...)

        I used Crosstools-NG for that, but I could use the official QNAP Maxwell-ARM Toolchain too (I saw it too late...)

        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)
        

        但问题一直存在,有一个节点依赖(libuv) 它使用一个名为 linux-atomic,该库从 4.4.X 版开始在 GCC 中引入.所以这是我修复它的解决方法:

        But a problem was always here, there's a node dependecy (libuv) which uses a library named linux-atomic, and that library was introduced in GCC since version 4.4.X. So here is the workaround I made to fix it :

        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
        

        解决方法参考

        使用该配置,我还可以为 x86 处理器使用 GCC 4.1.3 编译节点.我为不想自己编译的 QNAP 用户制作了 QPKG:https://github.com/jbltx/nodejs-QPKG/tree/master/node-v0.10.35

        With that configuration, I also could compile node with GCC 4.1.3 for x86 processors. And I made QPKG for QNAP users who doesn't want to compile by themselves : https://github.com/jbltx/nodejs-QPKG/tree/master/node-v0.10.35

        这篇关于armv5 交叉编译节点的库兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆