Skip to content

交叉编译+静态编译 #40

@shownb

Description

@shownb

armv7的交叉编译

apt-get update
apt-get install gcc-arm-linux-gnueabihf
apt-get install g++-arm-linux-gnueabihf 这个不装的后遗症是出现configure: error: C compiler cannot create executables

目标 tcpdump的静态编译
git clone https://github.com/the-tcpdump-group/libpcap
git clone git://bpf.tcpdump.org/tcpdump

编译libpcap

./configure --prefix=/root/libpcap --host=arm-linux CC=arm-linux-gnueabihf-gcc
make
make install

编译tcpdump
下面三个export不做的话,会在编译完成之后在目标机器运行的时 出现如下错误:
not found. 这真不是开玩笑,出现这个问题是,是因为,你不静态编译的话,他还会调用一些so库。
arm-linux-gnueabihf-readelf -e tcpdump 可以知道是不是会调用其他库。我在没有export之前,会出现[Requesting program interpreter: /lib/ld-linux-armhf.so.3]

export CFLAGS=-static
export CPPFLAGS=-static
export LDFLAGS=-static
./configure --prefix=/root/tcpdump --disable-ipv6  CC=arm-linux-gnueabihf-gcc --host=arm-linux CFLAGS='-I/root/libpcap/include' LDFLAGS='-L/root/libpcap/lib/libpcap.a'
或
./configure --prefix=/root/tcpdump CC=arm-linux-gnueabihf-gcc --host=arm-linux CFLAGS='-I/root/libpcap/include -static' CPPFLAGS='-static' LDFLAGS='-L/root/libpcap/lib/libpcap.a -static'
make

如果出现某些错误,还需要改一下configure 把那些对版本的注视掉.

./configure --prefix=/root/tcpdump CC=arm-linux-gnueabi-gcc --host=arm-linux CFLAGS='-I/root/libpcap/include -static' CPPFLAGS='-static' LDFLAGS='-L/root/libpcap/lib/libpcap.a -static' ac_cv_linux_vers=2 --with-crypto=no

再减减肥,完美了。
arm-linux-gnueabihf-strip tcpdump

静态编译lua

http://www.neptune8.com/post/lua交叉编译/

CROSS=arm-linux-gnueabihf-
CC=$(CROSS)gcc
LIBS= -lm $(SYSLIBS) -static
AR=$(CROSS)ar rcu
RANLIB=$(CROSS)ranlib
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline" 去掉最后的-lreadline

luaconf.h修改
需要把 #define LUA_USE_READLINE 注释掉

mips的交叉编译

apt-get install gcc-mips-linux-gnu
apt-get install g++-mips-linux-gnu

更多的交叉编译器
curl https://codescape.mips.com/components/toolchain/2017.10-08/Codescape.GNU.Tools.Package.2017.10-08.for.MIPS.MTI.Linux.CentOS-5.x86_64.tar.gz -O

一般编辑
nano /etc/bash.bashrc
添加编译器的路径
export PATH=/yourpatch/rsdk-1.5.10-5281-EB-2.6.30-0.9.30-m32ub-130429/bin:$PATH

source /etc/bash.bashrc

问题:

  1. 出现"kernel too old”"的原因是不同版本的glibc库文件要依赖于不同版本的linux内核版本,并且编译器会限定运行该可执行文件所需的最低的内核版本。在编译时使用的编译器的版本比较高,它所指定的最低linux内核版本要高于m5声明的内核版本。
    编译出来之后看看适用版本
    file tcpdump
    tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=7820526da766673fe27af2231cd7f89b4cd2a440, stripped

目标机器内核是:Linux 2.6.34.10

  1. rtk的破假mips

安装指定版本的软件
apt-get install openssh-client=1:6.6p1-2ubuntu1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions