当前位置: 代码迷 >> 综合 >> ubuntu18.04 zlib-1.2.11交叉编译
  详细解决方案

ubuntu18.04 zlib-1.2.11交叉编译

热度:43   发布时间:2023-12-25 15:38:30.0

1 代码下载

代码下载地址:

https://www.zlib.net/zlib-1.2.11.tar.gz

解压:

tar xvzf zlib-1.2.11.tar.gz
cd zlib-1.2.11

2 配置makefile

–prefix指明install路径,交叉编译一般安装在toolchain目录,下次编译其他的lib就可以直接使用了。

./configure --prefix=/usr/local/arm/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi

配置完成后还需修改一下,将编译器更换arm-linux-gcc,我使用的是4.4.3的版本。


# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
# make install
# To install in $HOME instead of /usr/local, use:
# make install prefix=$HOMECC=arm-none-linux-gnueabi-gccCFLAGS=-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-g -DZLIB_DEBUG
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
# -Wstrict-prototypes -Wmissing-prototypesSFLAGS=-O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
LDFLAGS=
TEST_LDFLAGS=-L. libz.a
LDSHARED=arm-none-linux-gnueabi-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
CPP=arm-none-linux-gnueabi-gcc -ESTATICLIB=libz.a
SHAREDLIB=libz.so
SHAREDLIBV=libz.so.1.2.11
SHAREDLIBM=libz.so.1
LIBS=$(STATICLIB) $(SHAREDLIBV)AR=arm-none-linux-gnueabi-ar
ARFLAGS=rc
RANLIB=arm-none-linux-gnueabi-ranlib
LDCONFIG=ldconfig
LDSHAREDLIBC=-lc
TAR=tar
SHELL=/bin/sh
EXE=prefix =/usr/local/arm/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi
exec_prefix =${prefix}
libdir =${exec_prefix}/lib
sharedlibdir =${libdir}
includedir =${prefix}/include
mandir =${prefix}/share/man
man3dir = ${mandir}/man3
pkgconfigdir = ${libdir}/pkgconfig
SRCDIR=
ZINC=
ZINCOUT=-I.

尤其是LDSHARED,gcc一定要替换成arm-none-linux-gnueabi-gcc ,否则会有如下错误。

/usr/bin/ld: adler32.lo: Relocations in generic ELF (EM: 40)
adler32.lo: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
Makefile:282: recipe for target 'libz.so.1.2.11' failed

3 编译

make
make insatll
  相关解决方案