2014-04-20 47 views
2

我不能包括在Android NDK本地庫zlib的頭zlib.h:我得到一個*致命錯誤:的Android NDK - 致命錯誤:zlib.h:沒有這樣的文件或目錄

zlib.h: No such file or directory

運行時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 

調試信息 - 環境變量:

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共享庫,但爲什麼我應該這樣做,因爲它應該是一個標準的「穩定的」NDK庫!

注意this沒有幫助:

Yes, sorry about that but this is really a bug in the NDK build scripts. Right now, you can replace:

LOCAL_LDLIBS := -lz

with

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

sorry about that, this will be fix in the next NDK release.

+0

實際上,Android NDK確實在所有平臺的** include **目錄中包含「zlib.h」。我想錯誤是CyanogenMod構建系統不使用「官方」NDK。 –

回答

0

看來線是一個錯誤。我們需要通過構建幷包括android_external_zlib來使用解決方法。如果最後使用這些CyanogenMod的構建系統在我的模塊Android.mk補充說:

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

但對於這個問題(3K +的意見)的龐大的受衆羣體,應該有人發佈了基於Android NDK只是一個完整的解決方案。

來源:@KrisWebDev

0

你可能缺少zlib的頭文件,嘗試安裝libz-dev開發包,例如

sudo apt-get install libz-dev 
+0

我不明白。你最近的「安裝libz-dev」的答案是什麼?這個基於Debian的答案如何普遍地做到這一點?爲什麼你在代表OP添加自我回答20分鐘後在這裏添加一個答案(你非常正確地這麼做)? –

+0

多個答案都很好。我已經轉發了OP的答案,因爲這是發佈的正確位置,但我不確定他的方法是否是解決問題的最終解決方案。這個解決'zlib.h:沒有這樣的文件或目錄錯誤直接通過安裝提供'zlib'頭文件的缺少開發包。 Apt-get非常常見,取決於您開發Android應用程序的位置。我可以看到OP基於路徑使用Linux。 – kenorb

+0

據我所知,apt-get默認只適用於debian和ubuntu。我可以接受,這是對所有這些問題的有效答案,但是你確定它們中的任何一個都不能作爲對方的重複關閉嗎?對於多個問題(我最初的問題提到的),主要的(接近)重複解答的答案是,如果相同的答案適用,那麼問題通常是重複的,在這種情況下,閉包是正確的行動。我並不是說你一定錯了,我只是想讓你確保你做的是正確的事情。 –

相關問題