头图

一、交叉编译bzip2

1. 下载libpng源码

下载bzip2https://sourceware.org/bzip2/downloads.html

下载并解压源码。

tar -xvzf bzip2-1.0.8.tar.gz
cd bzip2-1.0.8

2. 设置环境变量

设置交叉编译工具链的环境变量:

export PATH=/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin:$PATH

3. 修改 Makefile-libbz2_so

SHELL=/bin/bash
CC=arm-linux-gnueabihf-gcc

4. 生成Makefile

make -f Makefile-libbz2_so

输出示例:

yoyo@yoyo:~/360Downloads/bzip2-1.0.8$ make -f Makefile-libbz2_so
arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c blocksort.c
blocksort.c: In function ‘mainSort’:
blocksort.c:347:6: warning: inlining failed in call to ‘mainGtU’: --param max-inline-insns-single limit reached [-Winline]

arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c huffman.c
arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c crctable.c
arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c randtable.c
arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c compress.c
arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c decompress.c
arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzlib.c
arm-linux-gnueabihf-gcc -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.8 blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o
arm-linux-gnueabihf-gcc -fpic -fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -o bzip2-shared bzip2.c libbz2.so.1.0.8
rm -f libbz2.so.1.0
ln -s libbz2.so.1.0.8 libbz2.so.1.0

5. 修改Makefile

SHELL=/bin/bash
CC=arm-linux-gnueabihf-gcc
AR=arm-linux-gnueabihf-ar
RANLIB=arm-linux-gnueabihf-ranlib

PREFIX=/home/yoyo/360Downloads/bzip2-1.0.8/arm32_install

# all: libbz2.a bzip2 bzip2recover test
# 修改为
all: libbz2.a bzip2 bzip2recover

解释说明:将 all: libbz2.a bzip2 bzip2recover 后面的 test 删除,是因为bzip2在编译完后会生成一个bzip2的可执行文件,由于我们采用交叉编译工具生成的可执行文件是ARM体系的,在宿主机上自然是执行不了,也就会导致test失败。

6. 编译安装

# 编译
make -j8

# 安装
make install

make 编译:

yoyo@yoyo:~/360Downloads/bzip2-1.0.8$ make -j8
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c huffman.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c crctable.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c randtable.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c compress.c

If compilation produces errors, or a large number of warnings,
please read README.COMPILATION.PROBLEMS -- you might be able to
adjust the flags in this Makefile to improve matters.

Also in README.COMPILATION.PROBLEMS are some hints that may help
if your build produces an executable which is unable to correctly
handle so-called 'large files' -- files of size 2GB or more.

arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c blocksort.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c decompress.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzlib.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzip2.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -c bzip2recover.c
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64  -o bzip2recover bzip2recover.o
blocksort.c: In function ‘mainSort’:
blocksort.c:347:6: warning: inlining failed in call to ‘mainGtU’: --param max-inline-insns-single limit reached [-Winline]
rm -f libbz2.a
arm-linux-gnueabihf-ar cq libbz2.a blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o
arm-linux-gnueabihf-ranlib libbz2.a
arm-linux-gnueabihf-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64  -o bzip2 bzip2.o -L. -lbz2

make install 安装:

yoyo@yoyo:~/360Downloads/bzip2-1.0.8$ make install
if ( test ! -d /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin ) ; then mkdir -p /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin ; fi
if ( test ! -d /home/yoyo/360Downloads/bzip2-latest/arm32_install/lib ) ; then mkdir -p /home/yoyo/360Downloads/bzip2-latest/arm32_install/lib ; fi
if ( test ! -d /home/yoyo/360Downloads/bzip2-latest/arm32_install/man ) ; then mkdir -p /home/yoyo/360Downloads/bzip2-latest/arm32_install/man ; fi
if ( test ! -d /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1 ) ; then mkdir -p /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1 ; fi
if ( test ! -d /home/yoyo/360Downloads/bzip2-latest/arm32_install/include ) ; then mkdir -p /home/yoyo/360Downloads/bzip2-latest/arm32_install/include ; fi
cp -f bzip2 /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzip2
cp -f bzip2 /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bunzip2
cp -f bzip2 /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzcat
cp -f bzip2recover /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzip2recover
chmod a+x /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzip2
chmod a+x /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bunzip2
chmod a+x /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzcat
chmod a+x /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzip2recover
cp -f bzip2.1 /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1
chmod a+r /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzip2.1
cp -f bzlib.h /home/yoyo/360Downloads/bzip2-latest/arm32_install/include
chmod a+r /home/yoyo/360Downloads/bzip2-latest/arm32_install/include/bzlib.h
cp -f libbz2.a /home/yoyo/360Downloads/bzip2-latest/arm32_install/lib
chmod a+r /home/yoyo/360Downloads/bzip2-latest/arm32_install/lib/libbz2.a
cp -f bzgrep /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzgrep
ln -s -f /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzgrep /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzegrep
ln -s -f /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzgrep /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzfgrep
chmod a+x /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzgrep
cp -f bzmore /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzmore
ln -s -f /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzmore /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzless
chmod a+x /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzmore
cp -f bzdiff /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzdiff
ln -s -f /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzdiff /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzcmp
chmod a+x /home/yoyo/360Downloads/bzip2-latest/arm32_install/bin/bzdiff
cp -f bzgrep.1 bzmore.1 bzdiff.1 /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1
chmod a+r /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzgrep.1
chmod a+r /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzmore.1
chmod a+r /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzdiff.1
echo ".so man1/bzgrep.1" > /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzegrep.1
echo ".so man1/bzgrep.1" > /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzfgrep.1
echo ".so man1/bzmore.1" > /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzless.1
echo ".so man1/bzdiff.1" > /home/yoyo/360Downloads/bzip2-latest/arm32_install/man/man1/bzcmp.1

7. 移植到开发板

将编译好的文件,拷贝到开发板。

# 拷贝 include
cp -r ./arm32_install/include/* /PATH/TO/arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include

# 拷贝lib
cp -r ./arm32_install/lib/* /PATH/TO/arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib

技术交流群


花花少年
1 声望0 粉丝

本账号旨在记录和分享知识,不用于商业用途!