0

我正在尝试在 ubuntu 13.04 下编译 curl 源代码(版本 7.22.0)以将 libcurl 导入 Android 平台。Android源码(Android-2.2_r1版本)已经编译成功,curl编译环境搭建成功。

编译环境:

    Android Source Code version: 2.2_r1
    NDK Version:android-ndk-r8e
    Curl Souce Code version:7.22.0
    GCC version:4.4.7
    JDK version:1.5.0_21

下面是为 libcurl 设置编译环境的 configure 命令:

ANDROID_HOME=/home/kevin/Android-Build/working-space && \
NDK_HOME=/home/kevin/Software/android-ndk-r8e && \
PATH="$ANDROID_HOME/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin:$PATH" \
./configure --host=arm-linux CC=arm-eabi-gcc --with-random=/dev/urandom \
CPPFLAGS="-I$NDK_HOME/platforms/android-14/arch-arm/usr/include \
-I $ANDROID_HOME/external/curl/include/  \
-I $ANDROID_HOME/external/curl   \
-I $ANDROID_HOME/out/target/product/generic/obj/STATIC_LIBRARIES/libcurl_intermediates   \
-I $ANDROID_HOME/dalvik/libnativehelper/include/nativehelper   \
-I $ANDROID_HOME/system/core/include   \
-I $ANDROID_HOME/hardware/libhardware/include   \
-I $ANDROID_HOME/hardware/libhardware_legacy/include   \
-I $ANDROID_HOME/hardware/ril/include   \
-I $ANDROID_HOME/dalvik/libnativehelper/include   \
-I $ANDROID_HOME/frameworks/base/include   \
-I $ANDROID_HOME/frameworks/base/opengl/include   \
-I $ANDROID_HOME/frameworks/base/native/include   \
-I $ANDROID_HOME/external/skia/include   \
-I $ANDROID_HOME/out/target/product/generic/obj/include   \
-I $ANDROID_HOME/bionic/libc/arch-arm/include   \
-I $ANDROID_HOME/bionic/libc/include   \
-I $ANDROID_HOME/bionic/libstdc++/include   \
-I $ANDROID_HOME/bionic/libc/kernel/common   \
-I $ANDROID_HOME/bionic/libc/kernel/arch-arm   \
-I $ANDROID_HOME/bionic/libm/include   \
-I $ANDROID_HOME/bionic/libm/include/arch/arm   \
-I $ANDROID_HOME/bionic/libthread_db/include \
-include $ANDROID_HOME/system/core/include/arch/linux-arm/AndroidConfig.h \
-I $ANDROID_HOME/system/core/include/arch/linux-arm/ \
-D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DNDEBUG -DNDEBUG -DHAVE_CONFIG_H" \
CFLAGS="-fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections \
-funwind-tables -fstack-protector -Wa,--noexecstack -Werror=format-security \
-fno-short-enums -march=armv5te -mtune=xscale  -Wno-psabi -mthumb-interwork  \
-fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith \
-Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point  \
-g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once \
-fgcse-after-reload -frerun-cse-after-loop -frename-registers  -UDEBUG \
-mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64   \
-Wpointer-arith -Wwrite-strings -Wunused -Winline -Wnested-externs \
-Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal \
-Wno-multichar -Wsign-compare -Wno-format-nonliteral -Wendif-labels \
-Wstrict-prototypes -Wdeclaration-after-statement -Wno-system-headers"  \
LIBS="-nostdlib -Bdynamic -Wl,-T,$ANDROID_HOME/build/core/armelf.x \
-Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc \
-L$ANDROID_HOME/out/target/product/generic/obj/lib -Wl,-z,noexecstack \
-Wl,-rpath-link=$ANDROID_HOME/out/target/product/generic/obj/lib \
-lc -llog -lcutils -lstdc++ \
-Wl,--no-undefined $ANDROID_HOME/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/libgcc.a  \
 $ANDROID_HOME/out/target/product/generic/obj/lib/crtend_android.o \
-lm $ANDROID_HOME/out/target/product/generic/obj/lib/crtbegin_dynamic.o"

执行 config 命令后,我可以从 external/curl 目录下的 config.log 文件中看到以下内容

configure:21303: checking zlib.h usability
configure:21303: $? = 0
configure:21303: result: yes

configure:21303: checking zlib.h presence
configure:21303: $? = 0
configure:21303: result: yes

configure:21303: checking for zlib.h
configure:21303: result: yes
configure:21384: found both libz and libz.h header

我还检查了目录:$NDK_HOME/platforms/android-14/arch-arm/usr/include并确保 zlib.h 文件确实存在。

问题:当我尝试使用命令编译 libcurl 时,编译make libcurl失败。我得到的错误是:

In file included from external/curl/lib/base64.c:30:
external/curl/lib/urldata.h:141:59: error: zlib.h: No such file or directory
In file included from external/curl/lib/base64.c:30:
external/curl/lib/urldata.h:585: error: expected specifier-qualifier-list before 'z_stream'

这真的让我很沮丧,因为该文件确实存在并且在配置步骤中找到。

解决方案尝试: 我尝试将 NDK_HOME 中 zlib.h 文件的绝对路径添加到位于 external/curl 目录的 Android.mk 文件中,如下所示。

LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/ /home/kevin/Software/android-ndk-r8e/platforms/android-14/arch-arm/usr/include 

原来错误消失了,编译成功了,但是在程序中使用curl库时,出现如下错误:

/home/kevin/Software/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib/libcurl.a(content_encoding.o): in function Curl_unencode_deflate_write:external/curl/lib/content_encoding.c:180: error: undefined reference to 'inflateInit_'

有人有同样的问题吗?任何帮助是极大的赞赏。

4

1 回答 1

0

看起来您在构建程序时缺少 -lz 。

于 2013-07-11T03:28:14.130 回答