Android NDK - 致命错误:zlib.h:没有这样的文件或目录

时间:2014-04-20 13:07:28

标签: android android-ndk linker-errors zlib

我无法包含Android NDK本机库zlib标头 zlib.h :我收到*致命错误:

  

zlib.h:没有这样的文件或目录

运行mka hello_world

我正在使用CyanogenMod mka build命令编译(这是Android NDK)。

Android.mk档案:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS) 
LOCAL_SRC_FILES := test.c
LOCAL_MODULE      := hello_world  
LOCAL_LDLIBS      := -lz
include $(BUILD_EXECUTABLE)

test.c(此处不需要zlib,但这是示例):

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
int main()
{
     printf("Hello World\n");
     return 0;
}

调试信息 - 完整命令(mka showcommands):

prebuilts/misc/linux-x86/ccache/ccache prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc -I external/test -I /home/me/cm/out/target/product/galaxysmtd/obj/EXECUTABLES/hello_world_intermediates -I libnativehelper/include/nativehelper  -isystem system/core/include -isystem hardware/libhardware/include -isystem hardware/libhardware_legacy/include -isystem hardware/ril/include -isystem libnativehelper/include -isystem frameworks/native/include -isystem frameworks/native/opengl/include -isystem frameworks/av/include -isystem frameworks/base/include -isystem external/skia/include -isystem /home/me/cm/out/target/product/galaxysmtd/obj/include -isystem bionic/libc/arch-arm/include -isystem bionic/libc/include -isystem bionic/libstdc++/include -isystem bionic/libc/kernel/common -isystem bionic/libc/kernel/arch-arm -isystem bionic/libm/include -isystem bionic/libm/include/arm -isystem bionic/libthread_db/include -c  -fno-exceptions -Wno-multichar -msoft-float -fpic -fPIE -ffunction-sections -fdata-sections -funwind-tables -fstack-protector -Wa,--noexecstack -Werror=format-security -D_FORTIFY_SOURCE=2 -fno-short-enums -mcpu=cortex-a8 -mfloat-abi=softfp -mfpu=neon -include build/core/combo/include/arch/linux-arm/AndroidConfig.h -I build/core/combo/include/arch/linux-arm/ -Wno-unused-but-set-variable -fno-builtin-sin -fno-strict-volatile-bitfields -Wno-psabi -mthumb-interwork -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -DNEEDS_VECTORIMPL_SYMBOLS -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -DNDEBUG -g -Wstrict-aliasing=2 -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing       -MD -MF /home/me/cm/out/target/product/galaxysmtd/obj/EXECUTABLES/hello_world_intermediates/test.d -o /home/me/cm/out/target/product/galaxysmtd/obj/EXECUTABLES/hello_world_intermediates/test.o external/test/test.c

调试信息 - env vars:

ANDROID_BUILD_PATHS="/home/me/cm/out/host/linux-x86/bin:/home/me/cm/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin:/home/me/cm/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin:/home/me/cm/prebuilts/gcc/linux-x86/mips/mipsel-linux-android-4.7/bin:/home/me/cm/development/emulator/qtools:/home/me/cm/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin:/home/me/cm/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin:/home/me/cm/development/scripts:/home/me/cm/prebuilts/devtools/tools:"
ANDROID_BUILD_TOP="/home/me/cm"
ANDROID_DEV_SCRIPTS="/home/me/cm/development/scripts:/home/me/cm/prebuilts/devtools/tools"
ANDROID_EABI_TOOLCHAIN="/home/me/cm/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin"
ANDROID_HOST_OUT="/home/me/cm/out/host/linux-x86"
ANDROID_JAVA_TOOLCHAIN="/usr/lib/jvm/java-6-sun/bin"
ANDROID_PRE_BUILD_PATHS="/usr/lib/jvm/java-6-sun/bin:"
ANDROID_PRODUCT_OUT="/home/me/cm/out/target/product/galaxysmtd"
ANDROID_PROMPT_PREFIX="[arm-cm_galaxysmtd-userdebug]"
ANDROID_QTOOLS="/home/me/cm/development/emulator/qtools"
ANDROID_TOOLCHAIN="/home/me/cm/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin"
ARM_EABI_TOOLCHAIN="/home/me/cm/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin"

解决方法是使用编译zlib共享库,但为什么我应该这样做,因为它应该是标准的&#34;稳定&#34; NDK库!

注意this没有帮助:

  

是的,对不起,但这确实是NDK构建中的一个错误   脚本。现在,您可以替换:

     

LOCAL_LDLIBS := -lz

     

     

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -lz

     抱歉,这将在下一个NDK版本中修复。

2 个答案:

答案 0 :(得分:0)

看来这是一个错误。我们需要通过构建和包含android_external_zlib来使用解决方法。如果最终使用CyanogenMod构建系统,我的模块Android.mk中添加了这些:

LOCAL_C_INCLUDES    += $(LOCAL_PATH)/../zlib/src
LOCAL_SHARED_LIBRARIES  += libz

但是对于这个问题的大量观众(3k +观看次数),有人应该发布基于Android NDK的完整解决方案。

来源:@KrisWebDev

答案 1 :(得分:0)

您可能缺少zlib头文件,请尝试安装libz-dev开发包,例如。

sudo apt-get install libz-dev