title: Linking libpng to android native project
body: <p>I am having problems trying to load libpng in my native android project.
  It seems, that the compiler doesn't recognize libpng functions, but does recognize types (like png_byte). It compiles normally with types, but throws errors if I add functions.</p>
  
  <p>Here's compile output (windows 7 cmd):</p>
  
  <pre><code>D:\Dropbox\Workspace\Eclipse\GhostEngine\jni&gt;C:\android-ndk-r8\ndk-build
  "Compile++ thumb : ghost &lt;= ImagePng.cpp
  "Compile++ thumb : ghost &lt;= MainAndroid.cpp
  "Compile++ thumb : ghost &lt;= PlatformAndroid.cpp
  make: Circular D:/Dropbox/Workspace/Eclipse/GhostEngine//obj/local/armeabi/libst
  lport_static.a &lt;- D:/Dropbox/Workspace/Eclipse/GhostEngine//obj/local/armeabi/li
  bstlport_static.a dependency dropped.
  SharedLibrary  : libghost.so
  D:/Dropbox/Workspace/Eclipse/GhostEngine//obj/local/armeabi/objs/ghost/ImagePng.
  o: In function `loadPngFile':
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:48: undefined r
  eference to `png_sig_cmp'
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:55: undefined r
  eference to `png_create_read_struct'
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:61: undefined r
  eference to `png_create_info_struct'
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:68: undefined r
  eference to `png_create_info_struct'
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:75: undefined r
  eference to `png_set_longjmp_fn'
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:77: undefined r
  eference to `png_destroy_read_struct'
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:63: undefined r
  eference to `png_destroy_read_struct'
  D:/Dropbox/Workspace/Eclipse/GhostEngine//jni/ghost/ImagePng.cpp:70: undefined r
  eference to `png_destroy_read_struct'
  collect2: ld returned 1 exit status
  make: *** [D:/Dropbox/Workspace/Eclipse/GhostEngine//obj/local/armeabi/libghost.
  so] Error 1
  </code></pre>
  
  <p>My android.mk in libpng looks like this:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  LOCAL_CFLAGS := 
  
  LOCAL_MODULE    := libpng
  LOCAL_SRC_FILES :=\
      png.c \
      pngerror.c \
      pngget.c \
      pngmem.c \
      pngpread.c \
      pngread.c \
      pngrio.c \
      pngrtran.c \
      pngrutil.c \
      pngset.c \
      pngtrans.c \
      pngwio.c \
      pngwrite.c \
      pngwtran.c \
      pngwutil.c 
  
  LOCAL_LDLIBS := -lz
  
  include $(BUILD_STATIC_LIBRARY)
  </code></pre>
  
  <p>Application.mk:</p>
  
  <pre><code>APP_PLATFORM := android-10
  STLPORT_FORCE_REBUILD := true
  APP_STL := stlport_static
  APP_MODULES := libpng ghost
  #APP_CPPFLAGS += -fexceptions
  </code></pre>
  
  <p>Android.mk in my project folder:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  LOCAL_MODULE := ghost
  FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
  LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
  LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
  
  # Support for additional libraries
  #LOCAL_CFLAGS := -DANDROID_NDK -Wno-psabi
  LOCAL_STATIC_LIBRARIES := android_native_app_glue
  LOCAL_C_INCLUDES := $(LOCAL_PATH)/../libpng/
  LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -ldl
  LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -lz
  
  include $(BUILD_SHARED_LIBRARY)
  
  $(call import-module,android/native_app_glue)
  </code></pre>
  
  <p>I appreciate your help regarding this subject.
  Thanks, Martin.</p>