1

我正在尝试为 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。

感谢大家。

4

3 回答 3

1

因为你错过了“pnglibconf.h”文件,你可以在lpng/scripts/pnglibconf.h.prebuilt中找到它,只需将pnglibconf.h.prebuilt重命名为pnglibconf.h,然后添加到文件夹lpng中。您还需要修改文件:hpdf_image_png.c,在#include png.h 之后添加这一行:#include pnginfo.h。仅此而已,我相信你一定能成功。

于 2012-02-07T12:51:18.173 回答
1

使用 libpng 1.5 编译时,libharu 中有一个错误。

您可以应用此补丁: https ://github.com/tony2001/libharu/commit/e5bf8b01f6c3d5e3fe0e26ac5345e0da10c03934

于 2011-09-02T08:05:20.123 回答
0

我使用来自 jimtoner 的答案。几乎是对的。但是在我的情况下(lpng 1.6.3),我还需要修改文件:hpdf_image_png.c,在#include之后添加#include。它成功了!

于 2013-09-05T03:45:37.333 回答