我正在尝试为 Android 编译libharu。在我的jni文件夹中,我有:
- /jni/lpng154/包含 libpng 的所有源和包含文件;
- /jni/libharu-2.2.1/包含 libharu的所有源和包含文件
这是我的Android.mk(在/jni/文件夹中)。libharu 与 libpng 有依赖关系,所以我必须先编译 libpng。
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
sources := 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_C_INCLUDES := $(LOCAL_PATH)/lpng154
LOCAL_MODULE := png
LOCAL_LDLIBS := -lz
LOCAL_SRC_FILES := $(sources:%=lpng154/%)
include $(BUILD_STATIC_LIBRARY)
然后用于编译 libharu。
include $(CLEAR_VARS)
sources := hpdf_annotation.c \
hpdf_array.c \
hpdf_binary.c \
hpdf_boolean.c \
hpdf_catalog.c \
hpdf_destination.c \
hpdf_dict.c \
hpdf_doc.c \
hpdf_doc_png.c \
hpdf_encoder.c \
hpdf_encoder_cns.c \
hpdf_encoder_cnt.c \
hpdf_encoder_jp.c \
hpdf_encoder_kr.c \
hpdf_encrypt.c \
hpdf_encryptdict.c \
hpdf_error.c \
hpdf_ext_gstate.c \
hpdf_font.c \
hpdf_font_cid.c \
hpdf_fontdef_base14.c \
hpdf_fontdef.c \
hpdf_fontdef_cid.c \
hpdf_fontdef_cns.c \
hpdf_fontdef_cnt.c \
hpdf_fontdef_jp.c \
hpdf_fontdef_kr.c \
hpdf_fontdef_tt.c \
hpdf_fontdef_type1.c \
hpdf_font_tt.c \
hpdf_font_type1.c \
hpdf_gstate.c \
hpdf_image.c \
hpdf_image_png.c \
hpdf_info.c \
hpdf_list.c \
hpdf_mmgr.c \
hpdf_name.c \
hpdf_namedict.c \
hpdf_null.c \
hpdf_number.c \
hpdf_objects.c \
hpdf_outline.c \
hpdf_page_label.c \
hpdf_page_operator.c \
hpdf_pages.c \
hpdf_real.c \
hpdf_streams.c \
hpdf_string.c \
hpdf_u3d.c \
hpdf_utils.c \
hpdf_xref.c \
hpdf_pdfa.c
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/lpng154 \
$(LOCAL_PATH)/libharu-2.2.1/include \
$(LOCAL_PATH)/libharu-2.2.1/src
LOCAL_LDLIBS := -lz -lm
LOCAL_MODULE := haru
LOCAL_SRC_FILES := $(sources:%=libharu-2.2.1/src/%)
LOCAL_STATIC_LIBRARIES := z png
include $(BUILD_SHARED_LIBRARY)
当我运行ndk-buid时,编译器在尝试编译文件 *hpdf_image_png.c* 时停止,并出现许多错误,例如:
.../src/hpdf_image_png.c: In function 'ReadPngData_Interlaced':
.../src/hpdf_image_png.c:113: error: dereferencing pointer to incomplete type
.../src/hpdf_image_png.c:118: error: dereferencing pointer to incomplete type
.../src/hpdf_image_png.c:119: error: dereferencing pointer to incomplete type
.../src/hpdf_image_png.c:129: error: dereferencing pointer to incomplete type
...
...
我猜 ndk-build 找不到png.h ...我该如何帮助编译器找到标头?
如果在我的 Android.mk 中添加标志:
LOCAL_CFLAGS := -DLIBHPDF_HAVE_NOPNGLIB
在两行之前:
LOCAL_LDLIBS := -lz -lm
LOCAL_MODULE := haru
...
并运行ndk-build everithing 编译正常...但我会错过 libharu 中嵌入的 png。
感谢大家。