我正在尝试将ndk-build
创建的可执行文件链接到已使用NDK构建的现有.so库。这是我的Android.mk
文件:
LOCAL_PATH := $(call my-dir)/..
include $(CLEAR_VARS)
LOCAL_MODULE := mini_executor
LOCAL_C_INCLUDES := ../..
LOCAL_SRC_FILES := main.cpp
LOCAL_CXXFLAGS += -std=c++11
LOCAL_STATIC_LIBRARIES := mylib
include $(BUILD_EXECUTABLE)
当我尝试构建它时,我得到了大量未定义的引用,这对我来说意味着链接过程不起作用。果然,如果我在ndk-build上启用开关V=1
,我会看到以下几行:
"Compile++ thumb : mini_executor <= main.cpp
C:/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs/mini_executor/main.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I../.. -IC:/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.6/include -IC:/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include -IC:/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.6/include/backward -Ijni/.. -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -IC:/android-ndk-r9/platforms/android-3/arch-arm/usr/include -c jni/../main.cpp -o ./obj/local/armeabi/objs/mini_executor/main.o
Executable : mini_executor
C:/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=C:/android-ndk-r9/platforms/android-3/arch-arm ./obj/local/armeabi/objs/mini_executor/main.o C:/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a -lgcc -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm -o ./obj/local/armeabi/mini_executor
我唯一注意到的是,这些命令中没有任何地方可以链接到我在.mk文件中指定的现有.so文件。我已尝试同时使用LOCAL_SHARED_LIBRARIES
和LOCAL_STATIC_LIBRARIES
,但两者都没有做任何事情。它看起来好像甚至尝试链接到库。我在这里缺少什么?
答案 0 :(得分:2)
您需要在Android.mk文件中添加以下内容:
include $(CLEAR_VARS)
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := <path_to_mylib>/libmylib.a
include $(PREBUILT_STATIC_LIBRARY)
允许您的预建静态库包含在您的项目中。
查看docs / PREBUILTS.html以获取更多信息。