来点前奏说明
当你打开这个文档的时候,你已经做好准备了,话不多说开搞。
本文以https://github.com/libjpeg-turbo/libjpeg-turbo
的默认master分支进行编译,以Ubuntu进行演示编译过程。
1、硬件要求:
系统: Unbuntu
2、软件要求:
sudo apt install git
sudo apt install yasm
sudo apt install vim
sudo snap install cmake
NDK版本要求:NDK 14及其以前的版本
3、libjpeg 编译
git clone https://github.com/libjpeg-turbo/libjpeg-turbo.git
cd libjpeg-turbo/
Building libjpeg-turbo for Android platforms requires v13b or later of the Android NDK.
先放上我已经写好的shell脚本,以ARMv8 (64-bit)写的,为命名为build_arm64_android.sh
#!/bin/bash
# Set these variables to suit your needs
NDK_PATH=/home/zhangbin/Android/Sdk/ndk-bundle
#TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r14b and earlier,and "clang" must be used with NDK r17c and later}
TOOLCHAIN=gcc
#ANDROID_VERSION={the minimum version of Android to support. "21" or lateris required for a 64-bit build.}
ANDROID_VERSION=21
cmake -G"Unix Makefiles" \
-DANDROID_ABI=arm64-v8a \
-DANDROID_ARM_MODE=arm \
-DANDROID_PLATFORM=android-${ANDROID_VERSION} \
-DANDROID_TOOLCHAIN=${TOOLCHAIN} \
-DCMAKE_ASM_FLAGS="--target=aarch64-linux-android${ANDROID_VERSION}" \
-DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
ARMv7 (32-bit)
# Set these variables to suit your needs
NDK_PATH={full path to the NDK directory-- for example,
/opt/android/android-ndk-r16b}
TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r16b and earlier,
and "clang" must be used with NDK r17c and later}
ANDROID_VERSION={the minimum version of Android to support-- for example,
"16", "19", etc.}
cd {build_directory}
cmake -G"Unix Makefiles" \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_ARM_MODE=arm \
-DANDROID_PLATFORM=android-${ANDROID_VERSION} \
-DANDROID_TOOLCHAIN=${TOOLCHAIN} \
-DCMAKE_ASM_FLAGS="--target=arm-linux-androideabi${ANDROID_VERSION}" \
-DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
[additional CMake flags] {source_directory}
make
ARMv8 (64-bit)
# Set these variables to suit your needs
NDK_PATH={full path to the NDK directory-- for example,
/opt/android/android-ndk-r16b}
TOOLCHAIN={"gcc" or "clang"-- "gcc" must be used with NDK r14b and earlier,
and "clang" must be used with NDK r17c and later}
ANDROID_VERSION={the minimum version of Android to support. "21" or later
is required for a 64-bit build.}
cd {build_directory}
cmake -G"Unix Makefiles" \
-DANDROID_ABI=arm64-v8a \
-DANDROID_ARM_MODE=arm \
-DANDROID_PLATFORM=android-${ANDROID_VERSION} \
-DANDROID_TOOLCHAIN=${TOOLCHAIN} \
-DCMAKE_ASM_FLAGS="--target=aarch64-linux-android${ANDROID_VERSION}" \
-DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
[additional CMake flags] {source_directory}
make
执行上面写好的脚本,我的脚本命名为build_arm64_android.sh
./build_arm64_android.sh
Installing libjpeg-turbo
sudo make install
成功的标志,a文件为静态库,so文件为动态库
目录下面生成 libjpeg.a 和 libturbojpeg.a