來點(diǎn)前奏說明
當(dāng)你打開這個(gè)文檔的時(shí)候,你已經(jīng)做好準(zhǔn)備了,話不多說開搞。
本文以https://github.com/libjpeg-turbo/libjpeg-turbo
的默認(rèn)master分支進(jìn)行編譯,以Ubuntu進(jìn)行演示編譯過程。
1、硬件要求:
系統(tǒng): 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.
先放上我已經(jīng)寫好的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
執(zhí)行上面寫好的腳本,我的腳本命名為build_arm64_android.sh
./build_arm64_android.sh
Installing libjpeg-turbo
sudo make install
成功的標(biāo)志,a文件為靜態(tài)庫,so文件為動(dòng)態(tài)庫
目錄下面生成 libjpeg.a 和 libturbojpeg.a