嵌入式Linux开发之第三方库交叉编译

Posted PanGC2014

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了嵌入式Linux开发之第三方库交叉编译相关的知识,希望对你有一定的参考价值。

编译环境:第三方库源码存放在/data/library目录下,交叉编译工具链存放在/opt/toolchain目录下!!!

--------------------交叉编译bzip2--------------------

需要直接修改Makefile文件如下:

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
AR=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar
RANLIB=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ranlib
CFLAGS=-Wall -Winline -fPIC -O2 -g $(BIGFILES) PREFIX=/data/library/bzip2-1.0.6/_install
bzip2 -1  < sample1.ref > sample1.rb2
bzip2 -2  < sample2.ref > sample2.rb2
bzip2 -3  < sample3.ref > sample3.rb2
bzip2 -d  < sample1.bz2 > sample1.tst
bzip2 -d  < sample2.bz2 > sample2.tst
bzip2 -ds < sample3.bz2 > sample3.tst

--------------------交叉编译pcre-8.44--------------------

#!/bin/sh

mkdir -p _install

CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\ 
CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\ 
LD=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ld \\ 
AR=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar \\ 
RANLIB=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ranlib \\ 
STRIP=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip \\
./configure \\
    --prefix=$(pwd)/_install \\
    --host=arm-linux-gnueabi \\
    --build=i686-pc-linux

sleep 2

make clean && make all && make install

--------------------交叉编译zlib-1.2.11--------------------

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
./configure \\
    --prefix=$PWD/_install \\
    --host=arm-linux-gnueabi \\
    --build=i686-pc-linux

sleep 2

make clean && make all && make install

--------------------交叉编译lighttpd-1.4.54--------------------

注意:lighttpd依赖bzip2、pcre、zlib库

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\  
LD=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ld \\ 
AR=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar \\ 
RANLIB=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ranlib \\ 
STRIP=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip \\
PCRECONFIG=/data/library/pcre-8.44/_install/bin/pcre-config \\
LIBS="-L/data/library/pcre-8.44/_install/lib -L/data/library/zlib-1.2.11/_install/lib -L/data/library/bzip2-1.0.6/_install/lib" \\
CFLAGS="$CFLAGS -fPIC -DHAVE_PCRE_H=1 -DHAVE_LIBPCRE=1 -I/data/library/pcre-8.44/_install/include -I/data/library/zlib-1.2.11/_install/include -I/data/library/bzip2-1.0.6/_install/include" \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf --build=i686-pc-linux --enable-shared

sleep 2

make clean && make all && make install

--------------------交叉编译openssl-1.1.1f--------------------

#!/bin/sh

mkdir -p _install

./Configure --prefix=$(pwd)/_install linux-generic32 shared no-asm no-async CROSS_COMPILE=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- CC=gcc

sleep 2

make clean && make all && make install

-------------------交叉编译libevent-2.1.12----------------------

注意:libevent依赖openssl库

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\
LDFLAGS="-L/data/library/openssl-1.1.1f/_install/lib" CFLAGS="-I/data/library/openssl-1.1.1f/_install/include" \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf --build=i686-pc-linux

sleep 2

make clean && make all && make install

--------------------交叉编译libev-4.33--------------------

#!/bin/sh

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
./configure --prefix=$(pwd)/__install --host=arm-linux-gnueabihf --build=i686-pc-linux

sleep 2

make clean && make all && make install

--------------------交叉编译opencv_3.4.14--------------------

注意:opencv_contrib一定要与opencv版本对应!

#!/bin/sh
 
mkdir -p _install
 
mkdir -p build_arm
 
cd build_arm
 
echo "----- Setting up compilation"
 
cmake -DCMAKE_BUILD_TYPE=RELEASE \\
	-DCMAKE_INSTALL_PREFIX=/data/library/opencv_3.4.14/_install \\
	-DOPENCV_EXTRA_MODULES_PATH=/data/library/opencv_3.4.14/opencv_contrib/modules \\
	-DMAKE_C_COMPILER=/opt/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc \\
	-DMAKE_CXX_COMPILER=/opt/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ \\
	-DBUILD_SHARED_LIBS=ON ..
 
echo "----- Starting compilation"
 
make clean && make -j4 && make install
 
echo "----- OpenCV correctly built"

--------------------交叉编译x264--------------------

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc \\
./configure \\
	--prefix=$(pwd)/_install \\
	--host=arm-linux-gnueabi \\
	--cross-prefix=/opt/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi- \\
	--enable-static \\
	--enable-shared \\
	--disable-asm 

sleep 2

make clean && make -j4 && make install

--------------------交叉编译ffmpeg_4.2.4--------------------

#!/bin/sh
 
mkdir -p _install
 
CC=/opt/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc \\
./configure \\
    --prefix=$(pwd)/_install \\
    --cross-prefix=/opt/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi- \\
    --target-os=linux \\
    --arch=arm \\
    --disable-asm \\
    --enable-ffmpeg \\
    --disable-ffplay \\
    --enable-pthreads \\
    --enable-cross-compile \\
    --enable-gpl \\
    --enable-shared \\
    --enable-libx264 \\
    --extra-cflags=-I/data/library/x264_2021.06.09/_install/include \\
    --extra-ldflags=-L/data/library/x264_2021.06.09/_install/lib
 
sleep 2
 
make clean && make -j4 && make install

--------------------交叉编译curl-7.73.0--------------------

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf 

sleep 2

make clean && make all && make install

--------------------交叉编译curl-7.74.0--------------------

依赖于openssl所以需要先编译完openssl并加入资源路径

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf --enable-static --with-ssl=/data/library/openssl-1.1.1f/_install 

sleep 2

make clean && make all && make install

--------------------交叉编译apr-1.7.0--------------------

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_process_shared_works=yes apr_cv_mutex_robust_shared=yes apr_cv_tcp_nodelay_with_cork=yes ap_void_ptr_lt_long=no

sleep 2

make clean && make all && make install

--------------------交叉编译expat-2.2.10--------------------

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf --without-docbook

sleep 2

make clean && make all && make install

--------------------交叉编译apr-util-1.6.1--------------------

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
CXX=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf --with-apr=/data/library/apr-1.7.0/_install --with-expat=/data/library/expat-2.2.10/_install

sleep 2

make clean && make all && make install

--------------------交叉编译mxml-3.2--------------------

#!/bin/sh

mkdir -p _install

CC=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf --build=i686-pc-linux

sleep 2

make clean && make all && make install

--------------------交叉编译OSS C SDK--------------------

#!/bin/sh

mkdir -p _install

mkdir -p build_arm

cd build_arm

cmake -DCMAKE_BUILD_TYPE=Release \\
    -DCMAKE_INSTALL_PREFIX=/data/library/aliyun-oss-c-sdk-master/_install/ \\
    -DCMAKE_C_COMPILER=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \\
    -DCMAKE_CXX_COMPILER=/opt/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \\
    -DCURL_INCLUDE_DIR=/data/library/curl-7.73.0/_install/include/ \\
    -DCURL_LIBRARY=/data/library/curl-7.73.0/_install/lib/libcurl.a \\
    -DAPR_INCLUDE_DIR=/data/library/apr-1.7.0/_install/include/apr-1/ \\
    -DAPR_LIBRARY=/data/library/apr-1.7.0/_install/lib/libapr-1.a \\
    -DAPR_UTIL_INCLUDE_DIR=/data/library/apr-util-1.6.1/_install/include/apr-1 \\
    -DAPR_UTIL_LIBRARY=/data/library/apr-util-1.6.1/_install/lib/libaprutil-1.a \\
    -DMINIXML_INCLUDE_DIR=/data/library/mxml-2.12/_install/include/ \\
    -DMINIXML_LIBRARY=/data/library/mxml-2.12/_install/lib/libmxml.a ..

sleep 2

make clean && make all && make install

--------------------交叉编译glib--------------------

glib交叉编译依赖于libffi和zlib

mkdir _install

以上是关于嵌入式Linux开发之第三方库交叉编译的主要内容,如果未能解决你的问题,请参考以下文章

嵌入式Linux开发之第三方库交叉编译

x86 平台代码移植到 嵌入式平台[交叉编译三方库]

Linux aarch64交叉编译之libusb库

conan入门:conan 交叉编译引用第三方库示例

Linux aarch64交叉编译之glm数学库

Linux aarch64交叉编译之 cryptopp加密库