为 Android NDK 编译 XZ Utils

Posted

技术标签:

【中文标题】为 Android NDK 编译 XZ Utils【英文标题】:Compiling XZ Utils for Android NDK 【发布时间】:2013-09-17 15:34:41 【问题描述】:

我正在尝试编译 XZ-utils 代码以在 android NDK 中使用。我遵循与正确编译 libogg 和 libtheora 库相同的过程。但是,创建 XZ-Utils 的 liblzma 库不起作用。这是我使用的程序:

1) 转到包含库源的文件夹。

cd ~/Drivers/xz-5.0.5

2) 使用

配置 Autotool makefile
./configure --prefix=/home/rb/Drivers/xz --host=arm-linux-androideabi --target=arm-linux-androideabi --disable-shared --enable-static --enable-debug

3) 制作库并指定用于编译的工具链(位于/opt/ndk/):

make CC=/opt/ndk/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-gcc CXX=/opt/ndk/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-g++ LD=/opt/ndk/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-ld

运行第三条命令时,出现以下错误:

make  all-recursive
make[1]: Entering directory `/home/rb/Drivers/xz-5.0.5'
Making all in src
make[2]: Entering directory `/home/rb/Drivers/xz-5.0.5/src'
Making all in liblzma
make[3]: Entering directory `/home/rb/Drivers/xz-5.0.5/src/liblzma'
Making all in api
make[4]: Entering directory `/home/rb/Drivers/xz-5.0.5/src/liblzma/api'
make[4]: Nothing to be done for `all'.
make[4]: Leaving directory `/home/rb/Drivers/xz-5.0.5/src/liblzma/api'
make[4]: Entering directory `/home/rb/Drivers/xz-5.0.5/src/liblzma'
/bin/bash ../../libtool  --tag=CC   --mode=compile /opt/ndk/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-gcc -DHAVE_CONFIG_H -I. -I../..  -I../../src/liblzma/api -I../../src/liblzma/common -I../../src/liblzma/check -I../../src/liblzma/lz -I../../src/liblzma/rangecoder -I../../src/liblzma/lzma -I../../src/liblzma/delta -I../../src/liblzma/simple -I../../src/common -DTUKLIB_SYMBOL_PREFIX=lzma_  -pthread -fvisibility=hidden -Wall -Wextra -Wvla -Wformat=2 -Winit-self -Wmissing-include-dirs -Wstrict-aliasing -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wredundant-decls -g -O2 -MT liblzma_la-tuklib_physmem.lo -MD -MP -MF .deps/liblzma_la-tuklib_physmem.Tpo -c -o liblzma_la-tuklib_physmem.lo `test -f '../../src/common/tuklib_physmem.c' || echo './'`../../src/common/tuklib_physmem.c
libtool: compile:  /opt/ndk/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-gcc -DHAVE_CONFIG_H -I. -I../.. -I../../src/liblzma/api -I../../src/liblzma/common -I../../src/liblzma/check -I../../src/liblzma/lz -I../../src/liblzma/rangecoder -I../../src/liblzma/lzma -I../../src/liblzma/delta -I../../src/liblzma/simple -I../../src/common -DTUKLIB_SYMBOL_PREFIX=lzma_ -pthread -fvisibility=hidden -Wall -Wextra -Wvla -Wformat=2 -Winit-self -Wmissing-include-dirs -Wstrict-aliasing -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wredundant-decls -g -O2 -MT liblzma_la-tuklib_physmem.lo -MD -MP -MF .deps/liblzma_la-tuklib_physmem.Tpo -c ../../src/common/tuklib_physmem.c -o liblzma_la-tuklib_physmem.o
mv -f .deps/liblzma_la-tuklib_physmem.Tpo .deps/liblzma_la-tuklib_physmem.Plo
/bin/bash ../../libtool  --tag=CC   --mode=compile /opt/ndk/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-gcc -DHAVE_CONFIG_H -I. -I../..  -I../../src/liblzma/api -I../../src/liblzma/common -I../../src/liblzma/check -I../../src/liblzma/lz -I../../src/liblzma/rangecoder -I../../src/liblzma/lzma -I../../src/liblzma/delta -I../../src/liblzma/simple -I../../src/common -DTUKLIB_SYMBOL_PREFIX=lzma_  -pthread -fvisibility=hidden -Wall -Wextra -Wvla -Wformat=2 -Winit-self -Wmissing-include-dirs -Wstrict-aliasing -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wredundant-decls -g -O2 -MT liblzma_la-common.lo -MD -MP -MF .deps/liblzma_la-common.Tpo -c -o liblzma_la-common.lo `test -f 'common/common.c' || echo './'`common/common.c
libtool: compile:  /opt/ndk/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-gcc -DHAVE_CONFIG_H -I. -I../.. -I../../src/liblzma/api -I../../src/liblzma/common -I../../src/liblzma/check -I../../src/liblzma/lz -I../../src/liblzma/rangecoder -I../../src/liblzma/lzma -I../../src/liblzma/delta -I../../src/liblzma/simple -I../../src/common -DTUKLIB_SYMBOL_PREFIX=lzma_ -pthread -fvisibility=hidden -Wall -Wextra -Wvla -Wformat=2 -Winit-self -Wmissing-include-dirs -Wstrict-aliasing -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wredundant-decls -g -O2 -MT liblzma_la-common.lo -MD -MP -MF .deps/liblzma_la-common.Tpo -c common/common.c -o liblzma_la-common.o
In file included from common/common.c:13:
common/common.h:92: error: expected ';', ',' or ')' before 'in'
common/common.h:135: error: expected specifier-qualifier-list before 'lzma_code_function'
common/common.h:238: error: expected ';', ',' or ')' before 'in'
common/common.c:73: error: expected ';', ',' or ')' before 'in'
common/common.c: In function 'lzma_next_filter_update':
common/common.c:114: error: 'lzma_next_coder' has no member named 'update'
common/common.c:115: error: 'lzma_next_coder' has no member named 'update'
common/common.c: In function 'lzma_next_end':
common/common.c:126: error: 'lzma_next_coder' has no member named 'end'
common/common.c:127: error: 'lzma_next_coder' has no member named 'end'
common/common.c:133: error: unknown field 'code' specified in initializer
common/common.c:133: warning: initialization makes integer from pointer without a cast
common/common.c:133: warning: initialized field overwritten
common/common.c:133: warning: (near initialization for '(anonymous).init')
common/common.c:133: warning: initialized field overwritten
common/common.c:133: warning: (near initialization for '(anonymous).init')
common/common.c:133: error: unknown field 'end' specified in initializer
common/common.c:133: warning: excess elements in struct initializer
common/common.c:133: warning: (near initialization for '(anonymous)')
common/common.c:133: error: unknown field 'get_check' specified in initializer
common/common.c:133: warning: excess elements in struct initializer
common/common.c:133: warning: (near initialization for '(anonymous)')
common/common.c:133: error: unknown field 'memconfig' specified in initializer
common/common.c:133: warning: excess elements in struct initializer
common/common.c:133: warning: (near initialization for '(anonymous)')
common/common.c:133: error: unknown field 'update' specified in initializer
common/common.c:133: warning: excess elements in struct initializer
common/common.c:133: warning: (near initialization for '(anonymous)')
common/common.c: In function 'lzma_strm_init':
common/common.c:156: error: unknown field 'code' specified in initializer
common/common.c:156: warning: initialization makes integer from pointer without a cast
common/common.c:156: warning: initialized field overwritten
common/common.c:156: warning: (near initialization for '(anonymous).init')
common/common.c:156: warning: initialized field overwritten
common/common.c:156: warning: (near initialization for '(anonymous).init')
common/common.c:156: error: unknown field 'end' specified in initializer
common/common.c:156: warning: excess elements in struct initializer
common/common.c:156: warning: (near initialization for '(anonymous)')
common/common.c:156: error: unknown field 'get_check' specified in initializer
common/common.c:156: warning: excess elements in struct initializer
common/common.c:156: warning: (near initialization for '(anonymous)')
common/common.c:156: error: unknown field 'memconfig' specified in initializer
common/common.c:156: warning: excess elements in struct initializer
common/common.c:156: warning: (near initialization for '(anonymous)')
common/common.c:156: error: unknown field 'update' specified in initializer
common/common.c:156: warning: excess elements in struct initializer
common/common.c:156: warning: (near initialization for '(anonymous)')
common/common.c: In function 'lzma_code':
common/common.c:180: error: 'lzma_next_coder' has no member named 'code'
common/common.c:253: error: 'lzma_next_coder' has no member named 'code'
common/common.c: In function 'lzma_get_check':
common/common.c:331: error: 'lzma_next_coder' has no member named 'get_check'
common/common.c:334: error: 'lzma_next_coder' has no member named 'get_check'
common/common.c: In function 'lzma_memusage':
common/common.c:345: error: 'lzma_next_coder' has no member named 'memconfig'
common/common.c:346: error: 'lzma_next_coder' has no member named 'memconfig'
common/common.c: In function 'lzma_memlimit_get':
common/common.c:362: error: 'lzma_next_coder' has no member named 'memconfig'
common/common.c:363: error: 'lzma_next_coder' has no member named 'memconfig'
common/common.c: In function 'lzma_memlimit_set':
common/common.c:380: error: 'lzma_next_coder' has no member named 'memconfig'
common/common.c:386: error: 'lzma_next_coder' has no member named 'memconfig'
make[4]: *** [liblzma_la-common.lo] Error 1
make[4]: Leaving directory `/home/rb/Drivers/xz-5.0.5/src/liblzma'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/rb/Drivers/xz-5.0.5/src/liblzma'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/rb/Drivers/xz-5.0.5/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/rb/Drivers/xz-5.0.5'
make: *** [all] Error 2

我不知道是什么导致了这个错误,或者更重要的是,我不知道如何解决它。我搜索了这些错误,但找不到解决方案。对我来说,这似乎是源代码的 common/common.c 文件中的一个错误,但我认为这不太可能,因为其他人肯定会更早发现它。有人知道如何为 Android NDK 正确编译 XZ Utils 吗?

更新 我得到了要编译的库,尽管我仍然不知道上述过程有什么问题。编译通过配置makefile来工作

./configure --prefix=/home/rb/Drivers/xz --host=arm-linux-androideabi --target=arm-linux-androideabi --enable-static --with-pic --disable-xz --disable-xzdec --disable-lzmainfo --disable-scripts --disable-lzmadec --disable-shared

而不是make 命令,我直接使用make install 命令(具有相同的编译器路径)。

【问题讨论】:

你成功了吗? XZ for Java 非常慢,所以我必须为原生版本制作一个 JNI 包装器,所以如果你有一个可行的解决方案...... :-) 【参考方案1】:

构建 XZ 的步骤

您可以通过运行以下命令从其 git repo 下载 XZ:

git clone https://git.tukaani.org/xz.git

前者在构建各种架构时很有用;因此您可以运行(在源根目录中):

git clean -dfx
./autogen.sh

我的 NDK 位于 /home/osboxes/dev/android-ndk-r16b,因此我通过运行以下命令将其分为 3 个架构:

cd /home/osboxes/dev
~/dev/android-ndk-r16b/build/tools/make-standalone-toolchain.sh --use-llvm --arch=arm --install-dir=android-ndk-arm --force
~/dev/android-ndk-r16b/build/tools/make-standalone-toolchain.sh --use-llvm --arch=x86 --install-dir=android-ndk-x86 --force
~/dev/android-ndk-r16b/build/tools/make-standalone-toolchain.sh --use-llvm --arch=arm64 --install-dir=android-ndk-arm64 --force

对于 ARM

CC=~/dev/android-ndk-arm/bin/clang CFLAGS="-fPIE" LDFLAGS="-pie" ./configure --prefix=/home/osboxes/dev/libs/arm --host=arm-linux-androideabi --target=arm-linux-androideabi --enable-static --disable-xz --disable-xzdec --disable-lzmainfo --disable-scripts --disable-lzmadec --disable-shared

对于 ARM64

CC=~/dev/android-ndk-arm64/bin/clang CFLAGS="-fPIE" LDFLAGS="-pie" ./configure --prefix=/home/osboxes/dev/libs/arm64 --host=aarch64-linux-android --target=aarch64-linux-android --enable-static --with-pic --disable-xz --disable-xzdec --disable-lzmainfo --disable-scripts --disable-lzmadec --disable-shared

对于 x86

CC=~/dev/android-ndk-x86/bin/clang CFLAGS="-fPIE" LDFLAGS="-pie" ./configure --prefix=/home/osboxes/dev/libs/x86 --host=i686-linux-android --target=i686-linux-android --enable-static --disable-xz --disable-xzdec --disable-lzmainfo --disable-scripts --disable-lzmadec --disable-shared

每次配置后你必须运行:

make -j2

选项“-j2”使用 2 个 CPU 来构建进程。您可以更改要使用的 CPU 数量,甚至删除此选项。要安装编译的源代码,然后运行:

make install

【讨论】:

【参考方案2】:

只需将 configure 的 CC 指向您的交叉编译器并将其编译为 static 。不要使用任何其他标志

【讨论】:

以上是关于为 Android NDK 编译 XZ Utils的主要内容,如果未能解决你的问题,请参考以下文章

NDK <Utils/Log.h> 没有这样的文件或目录

Android NDK: 如何编译JNI为指定的指令集(armeabi/arm64)

将 Android Studio 配置为使用 NDK(android-ndk-r10d,Windows 64 位)

android开发,怎么使用ndk编译成.so文件

NDK 编译 Boringssl

如何用Android NDK编译FFmpeg