gpt4 book ai didi

c++ - 将 libpng 链接到 android native 项目

转载 作者:搜寻专家 更新时间:2023-10-31 01:14:31 25 4
gpt4 key购买 nike

我在尝试在我的 native android 项目中加载 libpng 时遇到问题。看起来,编译器无法识别 libpng 函数,但可以识别类型(如 png_byte)。它可以正常编译类型,但如果我添加函数就会抛出错误。

这是编译输出(windows 7 cmd):

D:\Dropbox\Workspace\Eclipse\GhostEngine\jni>C:\android-ndk-r8\ndk-build
"Compile++ thumb : ghost <= ImagePng.cpp
"Compile++ thumb : ghost <= MainAndroid.cpp
"Compile++ thumb : ghost <= PlatformAndroid.cpp
make: Circular D:/Dropbox/Workspace/Eclipse/GhostEngine//obj/local/armeabi/libst
lport_static.a <- 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

我在 libpng 中的 android.mk 看起来像这样:

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)

应用程序.mk:

APP_PLATFORM := android-10
STLPORT_FORCE_REBUILD := true
APP_STL := stlport_static
APP_MODULES := libpng ghost
#APP_CPPFLAGS += -fexceptions

Android.mk 在我的项目文件夹中:

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)

非常感谢您就此主题提供的帮助。谢谢,马丁。

最佳答案

我认为您可能需要将“libpng”添加到 LOCAL_STATIC_LIBRARIES 变量。

如果这不起作用,请尝试将 -lpng 添加到 Android.mk 文件中的 LOCAL_LD_LIBS 变量。 (需要哪个取决于libpng库放在哪里。)

关于c++ - 将 libpng 链接到 android native 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11265733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com