交叉编译 Protobuf、opencv、libwebsocke
2021-02-07 本文已影响0人
一钱科技
基于飞凌OK3399
Protobuf
- 下载:https://github.com/protocolbuffers/protobuf.git
- 解压,进入文件夹内
- 本地编译
./autogen.sh
./configure
make
sudo make install
./configure
- 交叉编译
make distclean
./configure --build=x86_64-pc-linux-gnu --host=aarch64-linux-gnu --with-protoc=protoc --prefix=/usr/aarch64-linux-gnu/protobuf
make
make check
sudo make install
--build表示本机环境,如果不清楚,在第一步,./configure时生成makefile时,查看打印信息,或插卡第一步生成的makefile
--host表示编译库的运行的环境,我的是arm架构cpu上运行,所以使用arm-linux,而生成的makefile中--host选项是arm-unknown-linux-gnu
--with-protoc=protoc,此选项的设置,是应为README.txt中所属,交叉编译需要增加此项,如果没有第一步得到部署protoc.exe,会出现错误,提示为:protoc找不到
opencv 本地
- 安装依赖项
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
- 编译
make build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
opencv 交叉编译
- 安装依赖项
apt-get install libavcodec-dev libavformat-dev libswscale-dev
- 安装依赖库
- zlib官网:http://www.zlib.net/
解压,进入文件夹内,设置输出目录
export CC=aarch64-linux-gnu-gcc
./configure --prefix=/usr/aarch64-linux-gnu/opencvdeps
make
sudo make install
- libjpeg下载地址:http://www.ijg.org/files/
./configure --host=aarch64-linux-gnu --prefix=/usr/aarch64-linux-gnu/opencvdeps --enable-shared --enable-static
make
make install
- libpng下载地址:http://www.libpng.org/pub/png/libpng.html
cp scripts/makefile.linux makefile
vim makefile
makefile中找到zlib相关的两行,修改成实际的zlib/lib和zlib/include,
再找到prefix项,修改为你想prefix的目录
如果此处是交叉编译的话,还需要在cc那边把gcc修改成您系统的交叉编译器,比如:arm-linux-gcc
make
make install
CC=aarch64-linux-gnu-gcc ./configure --enable-shared --host=aarch64-linux-gnu --disable-asm --prefix=/usr/aarch64-linux-gnu/opencvdeps
make
make install
CC=aarch64-linux-gnu-gcc ./configure --enable-shared --host=aarch64-linux-gnu --disable-asm --prefix=/usr/aarch64-linux-gnu/opencvdeps
make
make install
- libxvid下载地址:http://ftp.br.debian.org/debian-multimedia/pool/main/x/xvidcore/
进入libxvid的目录后,再行进入其子目录中:
cd ./build/generic
然后输入命令:
./configure --prefix=/usr/aarch64-linux-gnu/opencvdeps --host=aarch64-linux-gnu --disable-assembly
make
make install
- ffmpeg下载地址:http://ffmpeg.org/download.html
./configure --prefix=/usr/aarch64-linux-gnu/opencvdeps --enable-shared --disable-static --enable-gpl --enable-cross-compile --arch=arm64 --disable-stripping --target-os=linux --enable-libx264 --enable-libxvid --cc=aarch64-linux-gnu-gcc --enable-swscale --extra-ldflags=-L/usr/aarch64-linux-gnu/opencvdeps/lib --extra-cflags=-I/usr/aarch64-linux-gnu/opencvdeps/include
make
make install
- 编译opencv:
mkdir build
cd build
cmake \
-DWITH_PNG= OFF \
-DCMAKE_SYSTEM_PROCESSOR=aarch64-linux-gnu \
-DWITH_FFMPEG= ON \
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DCMAKE_AR=aarch64-linux-gnu-ar \
-DCMAKE_LINKER=aarch64-linux-gnu-ld \
-DCMAKE_NM=aarch64-linux-gnu-nm \
-DCMAKE_OBJCOPY=aarch64-linux-gnu-objcopy \
-DCMAKE_OBJDUMP=aarch64-linux-gnu-objdump \
-DCMAKE_RANLIB=aarch64-linux-gnu-ranlib \
-DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=/usr/aarch64-linux-gnu/opencv ..
make # 使用make -j,虚拟机有卡死的风险
sudo make install
openssl
- 下载:https://www.openssl.org/source/old/1.1.1/
- 解压,进入目录
- 交叉编译
export ARCH=arm64
./Configure linux-aarch64 no-asm shared --prefix=/usr/aarch64-linux-gnu/ssl CROSS_COMPILE=aarch64-linux-gnu-
make
make install
libwebsockets
- 下载
- 解压,进入目录
- 交叉编译
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr/aarch64-linux-gnu/libwebsocket \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_C_COMPILER=/usr/bin/aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/aarch64-linux-gnu-g++ \
-DZLIB_INCLUDE_DIR=/usr/aarch64-linux-gnu/zlib/include \
-DZLIB_LIBRARY="/usr/aarch64-linux-gnu/zlib/lib/libz.so" \
-DLWS_OPENSSL_INCLUDE_DIRS=/usr/aarch64-linux-gnu/ssl/include/ \
-DLWS_OPENSSL_LIBRARIES="/usr/aarch64-linux-gnu/ssl/lib/libssl.so;/usr/aarch64-linux-gnu/ssl/lib/libcrypto.so"
# 编译并安装
sudo make
sudo make install
qt
- 下载
- 解压,进入目录
- 修改qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf文件
./configure -prefix /home/forlinx/OK3399/qt \
-opensource \
-debug \
-confirm-license \
-xplatform linux-aarch64-gnu-g++ \
-no-opengl \
-no-pch \
-shared \
-no-iconv \
-no-xcb
- 交叉编译
./configure -prefix /home/forlinx/Downloads/qt \
-opensource \
-confirm-license \
-xplatform linux-aarch64-gnu-g++ \
-no-opengl \
-no-pch \
-shared \
-no-iconv \
-no-xcb
# 编译并安装
sudo make
sudo make install