分类 Ubuntu 下的文章

“Ubuntu是以桌面应用为主的Linux发行版,基于Debian。Ubuntu有三个正式版本,包括桌面版、服务器版及用于物联网设备和机器人的Core版。从17.10版本开始,Ubuntu以GNOME为默认桌面环境。 Ubuntu是著名的Linux发行版之一,也是目前最多用户的Linux版本。 ”

想在arm上使用node,好不容易移过去了,结果提示这个.这个时候可以试下patchelf,可能有用.
/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found。

ubuntu 20 安装 pathchelf

sudo apt install patchelf

查看命令帮助

patchelf -h

syntax: patchelf
[--set-interpreter FILENAME]
[--page-size SIZE]
[--print-interpreter]
[--print-soname] Prints 'DT_SONAME' entry of .dynamic section. Raises an error if DT_SONAME doesn't exist
[--set-soname SONAME] Sets 'DT_SONAME' entry to SONAME.
[--set-rpath RPATH]
[--remove-rpath]
[--shrink-rpath]
[--allowed-rpath-prefixes PREFIXES] With '--shrink-rpath', reject rpath entries not starting with the allowed prefix
[--print-rpath]
[--force-rpath]
[--add-needed LIBRARY]
[--remove-needed LIBRARY]
[--replace-needed LIBRARY NEW_LIBRARY]
[--print-needed]
[--no-default-lib]
[--debug]
[--version]
FILENAME

当前patchelf 版本

patchelf --version

patchelf 0.10

patchelf --print-interpreter node

/lib/ld-linux-armhf.so.3

patchelf --print-needed node

libdl.so.2
librt.so.1
libstdc++.so.6
libm.so.6
libgcc_s.so.1
libpthread.so.0
libc.so.6

修改interpreter

patchelf --set-interpreter /usr/local/lib/ld-linux-armhf.so.3 node

修改rpath

patchelf --set-rpath /usr/local/lib node

root@host:~# node -v

v8.11.1

root@host:~# cat /proc/cpuinfo 

Processor : ARMv7 Processor rev 2 (v7l)
BogoMIPS : 718.02
Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x3
CPU part : 0xc08
CPU revision : 2

Hardware : am335xevm
Revision : 0000
Serial : 0000000000000000

/lib/ld-linux-armhf.so.3 --list /usr/bin/node 

libdl.so.2 => /usr/local/lib/libdl.so.2 (0x4034a000)
librt.so.1 => /usr/local/lib/librt.so.1 (0x4006e000)
libstdc++.so.6 => /usr/local/lib/libstdc++.so.6 (0x4035d000)
libm.so.6 => /usr/local/lib/libm.so.6 (0x400b0000)
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1 (0x40125000)
libpthread.so.0 => /usr/local/lib/libpthread.so.0 (0x40160000)
libc.so.6 => /usr/local/lib/libc.so.6 (0x4024e000)
/usr/local/lib/ld-linux-armhf.so.3 => /lib/ld-linux-armhf.so.3 (0x40090000)

sudo apt install python-wheel-common

wheel unpack xxx.whl 

whl格式本质上是一个压缩包,里面包含了py文件,以及经过编译的pyd文件。使得可以在不具备编译环境的情况下,选择合适自己的python环境进行安装。
安装方法很简单,进入命令行输入

pip install xxxx.whl

或者如果是升级

pip install -U xxxx.whl

tcpdump 源码下载

wget https://www.tcpdump.org/release/tcpdump-4.99.1.tar.gz
wget https://www.tcpdump.org/release/libpcap-1.10.1.tar.gz

交叉编译libpcap

tar xvf libpcap-1.10.1.tar.gz
cd libpcap-1.10.1/
./configure --prefix=$(pwd)/.. --host=arm-linux-gnueabihf --with-pcap=linux --disable-shared
make && make install

交叉编译tcpdump

tar xvf tcpdump-4.99.1.tar.gz
cd tcpdump-4.99.1/
./configure --prefix=$(pwd)/.. --host=arm-linux-gnueabihf --with-crypto=$(pwd)/..
make && make install

如果不需要OpenSSL的话

./configure --prefix=$(pwd)/.. --host=arm-linux-gnueabihf

./tcpdump -h

compiler: hesy May 19 2022 08:51:08
tcpdump version 4.99.1
libpcap version 1.10.1 (with TPACKET_V3)
OpenSSL 1.1.1d 10 Sep 2019

tcpdump for arm 下载, 依赖OpenSSL
tcpdump for arm

iconv source code linux

wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz

交叉编译 libiconv

tar xvf libiconv-1.17.tar.gz
cd libiconv-1.17/
./configure --prefix=$(pwd)/.. --host=arm-linux-gnueabihf
make && make install

生成静态库

./configure --prefix=$(pwd)/.. --host=arm-linux-gnueabihf --enable-static
make -j
find . -type f -name "*.a"

./lib/.libs/libiconv.a
./lib/libcharset.a
./libcharset/lib/.libs/libcharset.a
./srclib/libicrt.a

find . -type f -name "*.so*"

./lib/.libs/libiconv.so.2.6.1
./lib/libcharset.so.1.0.0
./libcharset/lib/.libs/libcharset.so.1.0.0
生成动态库

./configure --prefix=$(pwd)/.. --host=arm-linux-gnueabihf --enable-shared
make -j
find . -type f -name "*.a"

./lib/libcharset.a
./libcharset/lib/.libs/libcharset.a
./srclib/libicrt.a

find . -type f -name "*.so*"

./lib/.libs/libiconv.so.2.6.1
./lib/libcharset.so.1.0.0
./libcharset/lib/.libs/libcharset.so.1.0.0

iconv c++ 转码示例

int utf82gbk(string instr, string& outstr)
{
    iconv_t cd = iconv_open("gbk", "utf-8");
    size_t inbytesleft = instr.length();
    size_t outbytesleft = 3 * inbytesleft;
    char* outbuf = (char*)malloc(outbytesleft);
    memset(outbuf, 0, outbytesleft);
    size_t bytes = outbytesleft;
    char* inbuf = (char*)malloc(inbytesleft);
    memcpy(inbuf, instr.data(), instr.length());

    char* srcstart = inbuf;
    char* tempoutbuf = outbuf;

    int ret = iconv(cd, &srcstart, &inbytesleft, &tempoutbuf, &outbytesleft);
    if (ret < 0)
    {
        perror("iconv");
        free(inbuf);
        free(outbuf);
        return -1;
    }
    bytes -= outbytesleft;
    iconv_close(cd);
    outstr.assign((char*)outbuf, bytes);
    free(inbuf);
    free(outbuf);

    return 0;
}

int gbk2utf8(string instr, string& outstr)
{
    iconv_t cd = iconv_open("utf-8", "gbk");
    size_t inbytesleft = instr.length();
    size_t outbytesleft = 3 * inbytesleft;
    char* outbuf = (char*)malloc(outbytesleft);
    memset(outbuf, 0, outbytesleft);
    size_t bytes = outbytesleft;
    char* inbuf = (char*)malloc(inbytesleft);
    memcpy(inbuf, instr.data(), instr.length());

    char* srcstart = inbuf;
    char* tempoutbuf = outbuf;

    int ret = iconv(cd, &srcstart, &inbytesleft, &tempoutbuf, &outbytesleft);
    if (ret < 0)
    {
        perror("iconv");
        free(inbuf);
        free(outbuf);
        return -1;
    }
    bytes -= outbytesleft;
    iconv_close(cd);
    outstr.assign((char*)outbuf, bytes);
    free(inbuf);
    free(outbuf);

    return 0;
}