我正在尝试为我的 NativeActivity 应用程序构建一个库并使用它,但它给了我一个错误:
拥有这些文件:
-jni/
--android.mk
--application.mk
--main.cpp
--png/
---android.mk
---lodepng.c
---lodepng.h
里面的 android.mkjni/png/
是这样的:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := lodepng
LOCAL_SRC_FILES := lodepng.c
# LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS := -DLODEPNG_NO_COMPILE_ENCODER -DLODEPNG_NO_COMPILE_DISK -DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS -DLODEPNG_NO_COMPILE_CPP
include $(BUILD_STATIC_LIBRARY)
里面的 android.mkjni/
是这样的:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myapp
LOCAL_SRC_FILES := main.cpp
# LOCAL_C_INCLUDES := $(LOCAL_PATH)/png
LOCAL_CFLAGS := -DANDROID
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := lodepng android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
include $(LOCAL_PATH)/png/android.mk
$(call import-module,android/native_app_glue)
(我已经评论了 C_INCLUDES,因为我不确定我是否需要它们。使用与否对结果没有区别)。
当我尝试编译它时,我得到的错误是这个:
C:\workspace\myapp> C:\cygwin\bin\bash --login -c "ndk-build -C ."
Compile++ thumb : myapp <= main.cpp
Compile thumb : lodepng <= lodepng.c
StaticLibrary : liblodepng.a
SharedLibrary : libmyapp.so
C:/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/..
/lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
./obj/local/armeabi/objs/myapp/main.o: in function init():jni/main.cpp:194:
error: undefined reference to 'lodepng_decode32(unsigned char**, unsigned int*,
unsigned int*, unsigned char const*, unsigned int)'
C:/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/..
/lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
./obj/local/armeabi/objs/myapp/main.o: in function init():jni/main.cpp:196:
error: undefined reference to 'lodepng_error_text(unsigned int)'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libmyapp.so] Error 1
在简历中,就像代码找不到此库的标头一样。尽管如此,它确实可以编译,所以这不是问题......
我应该编辑什么才能使用它?