title: Android NDK - fatal error: zlib.h: No such file or directory
body: <p>I can't include the Android NDK native library zlib header <strong>zlib.h</strong>: I get a *fatal error:</p>
  
  <blockquote>
    <p><strong>zlib.h: No such file or directory</strong></p>
  </blockquote>
  
  <p>when running <code>mka hello_world</code>.</p>
  
  <p>I am compiling using CyanogenMod mka build command (this is Android NDK).</p>
  
  <p><code>Android.mk</code> file:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS) 
  LOCAL_SRC_FILES := test.c
  LOCAL_MODULE      := hello_world  
  LOCAL_LDLIBS      := -lz
  include $(BUILD_EXECUTABLE)
  </code></pre>
  
  <p>test.c (zlib not needed here but this is for the example):</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;zlib.h&gt;
  int main()
  {
       printf("Hello World\n");
       return 0;
  }
  </code></pre>
  
  <p>Debug information - full command (mka showcommands):</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Debug information - env vars:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>The workaround is to use compile the zlib shared library, but why should I do it as it's supposed to be a standard "stable" NDK library!  </p>
  
  <p>Note <a href="https://groups.google.com/d/msg/android-ndk/VwsGXb8tzTI/GPxWM6H6TnkJ" rel="nofollow">this</a> didn't help:</p>
  
  <blockquote>
    <p>Yes, sorry about that but this is really a bug in the NDK build
    scripts. Right now, you can replace:</p>
    
    <p><code>LOCAL_LDLIBS := -lz</code></p>
    
    <p>with</p>
    
    <p><code>LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -lz</code></p>
    
    <p>sorry about that, this will be fix in the next NDK release.</p>
  </blockquote>