头图

一、参考资料

Ubuntu系统下交叉编译szip-CSDN博客

二、交叉编译szip

1. 下载源码

下载 Sziphttps://docs.hdfgroup.org/archive/support/doc_resource/SZIP/i...

下载并解压源码。

tar -xvzf szip-2.1.1.tar.gz
cd tar -xvzf szip-2.1.1
mkdir szipbuild

在这里插入图片描述

2. 设置环境变量

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

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

3. 生成configure配置

CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ ./configure \
--prefix=/home/yoyo/360Downloads/szip-2.1.1/szipbuild \
--host=arm-linux-gnueabihf

输出示例:

yoyo@ubuntu:~/360Downloads/szip-2.1.1$ CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ ./configure \
> --prefix=/home/yoyo/360Downloads/szip-2.1.1/szipbuild \
> --host=arm-linux-gnueabihf
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-gnueabihf-strip... arm-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-unknown-linux-gnueabihf
checking for config arm-unknown-linux-gnueabihf... no
checking for config arm-unknown-linux-gnueabihf... no
checking for config unknown-linux-gnueabihf... no
checking for config unknown-linux-gnueabihf... no
checking for config arm-linux-gnueabihf... no
checking for config arm-linux-gnueabihf... no
checking for config arm-unknown... no
checking for config linux-gnueabihf... no
checking for config linux-gnueabihf... no
checking for config unknown... no
checking for config arm... no
checking for arm-linux-gnueabihf-gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-gnueabihf-gcc accepts -g... yes
checking for arm-linux-gnueabihf-gcc option to accept ISO C89... none needed
checking whether arm-linux-gnueabihf-gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of arm-linux-gnueabihf-gcc... gcc3
checking how to run the C preprocessor... arm-linux-gnueabihf-gcc -E
checking for ar... ar
checking whether make sets $(MAKE)... (cached) yes
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by arm-linux-gnueabihf-gcc... /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld
checking if the linker (/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm -B
checking the name lister (/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-unknown-linux-gnu file names to arm-unknown-linux-gnueabihf format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld option to reload object files... -r
checking for arm-linux-gnueabihf-objdump... arm-linux-gnueabihf-objdump
checking how to recognize dependent libraries... pass_all
checking for arm-linux-gnueabihf-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for arm-linux-gnueabihf-ar... (cached) ar
checking for archiver @FILE support... @
checking for arm-linux-gnueabihf-strip... (cached) arm-linux-gnueabihf-strip
checking for arm-linux-gnueabihf-ranlib... arm-linux-gnueabihf-ranlib
checking command to parse /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm -B output from arm-linux-gnueabihf-gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for arm-linux-gnueabihf-mt... no
checking for mt... mt
configure: WARNING: using cross tools not prefixed with host triplet
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if arm-linux-gnueabihf-gcc supports -fno-rtti -fno-exceptions... no
checking for arm-linux-gnueabihf-gcc option to produce PIC... -fPIC -DPIC
checking if arm-linux-gnueabihf-gcc PIC flag -fPIC -DPIC works... yes
checking if arm-linux-gnueabihf-gcc static flag -static works... yes
checking if arm-linux-gnueabihf-gcc supports -c -o file.o... yes
checking if arm-linux-gnueabihf-gcc supports -c -o file.o... (cached) yes
checking whether the arm-linux-gnueabihf-gcc linker (/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking for shl_load... no
checking for shl_load in -ldld... no
checking for dlopen... no
checking for dlopen in -ldl... yes
checking whether a program can dlopen itself... cross
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for build mode... production
checking for math library support... no
checking for ANSI C header files... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for size_t... yes
checking for error_at_line... yes
checking for working memcmp... no
checking for vprintf... yes
checking for _doprnt... no
checking for memset... yes
checking if encoding enabled... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating test/Makefile
config.status: creating src/SZconfig.h
config.status: src/SZconfig.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands

4. 编译安装

# 编译
make -j8

# 安装
make install

make 编译:

yoyo@yoyo:~/360Downloads/szip-2.1.1$ make -j8
Making all in src
make[1]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1/src'
make  all-am
make[2]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1/src'
/bin/bash ../libtool  --tag=CC   --mode=compile arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I.     -O2  -MT rice.lo -MD -MP -MF .deps/rice.Tpo -c -o rice.lo rice.c
/bin/bash ../libtool  --tag=CC   --mode=compile arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I.     -O2  -MT sz_api.lo -MD -MP -MF .deps/sz_api.Tpo -c -o sz_api.lo sz_api.c
/bin/bash ../libtool  --tag=CC   --mode=compile arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I.     -O2  -MT encoding.lo -MD -MP -MF .deps/encoding.Tpo -c -o encoding.lo encoding.c
libtool: compile:  arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -O2 -MT rice.lo -MD -MP -MF .deps/rice.Tpo -c rice.c  -fPIC -DPIC -o .libs/rice.o
libtool: compile:  arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -O2 -MT sz_api.lo -MD -MP -MF .deps/sz_api.Tpo -c sz_api.c  -fPIC -DPIC -o .libs/sz_api.o
libtool: compile:  arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -O2 -MT encoding.lo -MD -MP -MF .deps/encoding.Tpo -c encoding.c  -fPIC -DPIC -o .libs/encoding.o
libtool: compile:  arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -O2 -MT encoding.lo -MD -MP -MF .deps/encoding.Tpo -c encoding.c -o encoding.o >/dev/null 2>&1
mv -f .deps/encoding.Tpo .deps/encoding.Plo
libtool: compile:  arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -O2 -MT sz_api.lo -MD -MP -MF .deps/sz_api.Tpo -c sz_api.c -o sz_api.o >/dev/null 2>&1
mv -f .deps/sz_api.Tpo .deps/sz_api.Plo
libtool: compile:  arm-linux-gnueabihf-gcc -DHAVE_CONFIG_H -I. -O2 -MT rice.lo -MD -MP -MF .deps/rice.Tpo -c rice.c -o rice.o >/dev/null 2>&1
mv -f .deps/rice.Tpo .deps/rice.Plo
/bin/bash ../libtool  --tag=CC   --mode=link arm-linux-gnueabihf-gcc  -O2  -version-info 2:0:0  -o libsz.la -rpath /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib rice.lo sz_api.lo encoding.lo  -lm
libtool: link: arm-linux-gnueabihf-gcc -shared  -fPIC -DPIC  .libs/rice.o .libs/sz_api.o .libs/encoding.o   -lm  -O2   -Wl,-soname -Wl,libsz.so.2 -o .libs/libsz.so.2.0.0
libtool: link: (cd ".libs" && rm -f "libsz.so.2" && ln -s "libsz.so.2.0.0" "libsz.so.2")
libtool: link: (cd ".libs" && rm -f "libsz.so" && ln -s "libsz.so.2.0.0" "libsz.so")
libtool: link: ar cru .libs/libsz.a  rice.o sz_api.o encoding.o
ar: `u' modifier ignored since `D' is the default (see `U')
libtool: link: arm-linux-gnueabihf-ranlib .libs/libsz.a
libtool: link: ( cd ".libs" && rm -f "libsz.la" && ln -s "../libsz.la" "libsz.la" )
make[2]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1/src'
make[1]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1/src'
Making all in test
make[1]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1/test'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1/test'
make[1]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1'
make[1]: Nothing to be done for 'all-am'.
make[1]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1'

make install 安装:

yoyo@yoyo:~/360Downloads/szip-2.1.1$ make install
Making install in src
make[1]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1/src'
make[2]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1/src'
 /usr/bin/mkdir -p '/home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib'
 /bin/bash ../libtool   --mode=install /usr/bin/install -c   libsz.la '/home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib'
libtool: install: /usr/bin/install -c .libs/libsz.so.2.0.0 /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib/libsz.so.2.0.0
libtool: install: (cd /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib && { ln -s -f libsz.so.2.0.0 libsz.so.2 || { rm -f libsz.so.2 && ln -s libsz.so.2.0.0 libsz.so.2; }; })
libtool: install: (cd /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib && { ln -s -f libsz.so.2.0.0 libsz.so || { rm -f libsz.so && ln -s libsz.so.2.0.0 libsz.so; }; })
libtool: install: /usr/bin/install -c .libs/libsz.lai /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib/libsz.la
libtool: install: /usr/bin/install -c .libs/libsz.a /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib/libsz.a
libtool: install: chmod 644 /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib/libsz.a
libtool: install: arm-linux-gnueabihf-ranlib /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib/libsz.a
libtool: finish: PATH="/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin:/home/yoyo/360Downloads/cmake-3.31.3-linux-x86_64/bin:/home/yoyo/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin" ldconfig -n /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /home/yoyo/360Downloads/szip-2.1.1/szipbuild/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
 /usr/bin/mkdir -p '/home/yoyo/360Downloads/szip-2.1.1/szipbuild/include'
 /usr/bin/install -c -m 644 ricehdf.h szip_adpt.h szlib.h '/home/yoyo/360Downloads/szip-2.1.1/szipbuild/include'
make[2]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1/src'
make[1]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1/src'
Making install in test
make[1]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1/test'
make[2]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1/test'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1/test'
make[1]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1/test'
make[1]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1'
make[2]: Entering directory '/home/yoyo/360Downloads/szip-2.1.1'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1'
make[1]: Leaving directory '/home/yoyo/360Downloads/szip-2.1.1'

5. 移植到开发板

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

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

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

技术交流群


花花少年
1 声望0 粉丝

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