为Android NDK编译XZ Utils

时间:2013-09-17 15:34:42

标签: android-ndk static-libraries lzma xz

我正在尝试编译用于​​Android NDK的XZ-utils代码。我遵循我用来正确编译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

运行第3个命令时,出现以下错误:

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命令(具有相同的编译器路径)。

2 个答案:

答案 0 :(得分:1)

构建XZ的步骤

您可以通过运行以下命令从XZ的git仓库下载XZ:

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

在为各种体系结构进行构建时,前者非常有用;这样就可以运行(在源根目录中):

git clean -dfx
./autogen.sh

我在 / home / osboxes / dev / android-ndk-r16b 中有我的NDK,因此我通过运行以下命令将其分为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

答案 1 :(得分:0)

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