我正在尝试将C静态库链接到C ++共享库,但似乎共享库完全忽略了LOCAL_STATIC_LIBRARIES行,并且没有链接静态库。
TextureEngine是静态库,CustomTexture是共享库。这是make文件
静态库 - TextureEngine
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := TextureEngine
LOCAL_SRC_FILES := ../TextureEngine.c
# LOCAL_SHARED_LIBRARIES :=
#LOCAL_LDLIBS := -llog -landroid -lGLESv2
include $(BUILD_STATIC_LIBRARY)
Application.mk:
APP_ABI := all
APP_PLATFORM := android-23
APP_MODULES := TextureEngine
共享库 - CustomTexture
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := TextureEngine
LOCAL_SRC_FILES := \
../TextureEngine/obj/local/$(TARGET_ARCH_ABI)/libTextureEngine.a
LOCAL_LDLIBS += -landroid -lGLESv2 -lm -lz -llog
include $(PREBUILT_STATIC_LIBARAY)
include $(CLEAR_VARS)
LOCAL_MODULE := CustomTexture
LOCAL_STATIC_LIBRARIES := TextureEngine
LOCAL_C_INCLUDES := ../TextureEngine
LOCAL_SRC_FILES := \
../CustomTexture.cpp \
../TextureProvider.cpp \
../Logfile.c \
../SineImage.cpp
LOCAL_LDLIBS += -landroid -lGLESv2 -lm -lz -llog
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS += -std=c++11
APP_ABI := all
APP_PLATFORM := android-23
当我在TextureEngine上运行ndk-build时,我会在所有架构文件夹上获得libTextureEngine.a文件。但是当我在CustomTexture上运行ndk-build时,我得到了未定义的引用。
在CustomTexture上运行带有V = 1的ndk-build
[arm64-v8a] SharedLibrary : libCustomTexture.so
/opt/android-ndk-r12b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-g++ -Wl,-soname,libCustomTexture.so -shared --sysroot=/opt/android-ndk-r12b/platforms/android-23/arch-arm64 ./obj/local/arm64-v8a/objs/CustomTexture/__/CustomTexture.o ./obj/local/arm64-v8a/objs/CustomTexture/__/TextureProvider.o ./obj/local/arm64-v8a/objs/CustomTexture/__/Logfile.o ./obj/local/arm64-v8a/objs/CustomTexture/__/SineImage.o /opt/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a -lgcc -no-canonical-prefixes -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/opt/android-ndk-r12b/platforms/android-23/arch-arm64/usr/lib -landroid -lGLESv2 -lm -lz -llog -lc -lm -o ./obj/local/arm64-v8a/libCustomTexture.so
正如您可能看到的那样 - TextureEngine不会出现在链接器行中。果然,我可以在CustomTexture的Android.mk的预构建部分更改LOCAL_SRC_FILES - 并且不会出现新的错误。
为什么ndk-build没有尝试并链接TextureEngine?
答案 0 :(得分:3)
include $(PREBUILT_STATIC_LIBARAY)
因为这里有拼写错误。 LIBRARY
,而不是LIBARAY
:)
我昨晚发现了一个错误,LOCAL_STATIC_LIBRARIES
或LOCAL_SHARED_LIBRARIES
中不存在的模块实际上不会导致错误,这就解释了为什么它很容易让这种错误错误,并且在构建中没有任何明显的错误。