【问题标题】:Compiling libharu with Android NDK使用 Android NDK 编译 libharu
【发布时间】:2011-10-25 19:30:39
【问题描述】:

我正在尝试为 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 一切编译正常...但我会错过 libharu 中嵌入的 png。

谢谢大家。

【问题讨论】:

    标签: android android-ndk libharu


    【解决方案1】:

    使用 libpng 1.5 编译时,libharu 中存在错误。

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 2014-05-03
          • 1970-01-01
          • 2014-02-14
          • 2011-08-15
          • 2011-07-09
          • 1970-01-01
          • 1970-01-01
          • 2014-09-11
          • 2011-09-29
          相关资源
          最近更新 更多