如何在Android.mk中包含静态第三方库?

时间:2016-08-30 18:26:03

标签: android android-ndk ros

我正在尝试使用Android.mk在静态库中进行链接,但是收到以下错误。

/home/pep/tools/crystax-ndk-10.3.2/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=/home/pep/tools/crystax-ndk-10.3.2/platforms/android-21/arch-arm -Wl,-rpath-link=/home/pep/tools/crystax-ndk-10.3.2/platforms/android-21/arch-arm/usr/lib -Wl,-rpath-link=/home/pep/workspace/elm/src/agents/viga/obj/local/armeabi-v7a /home/pep/workspace/elm/src/agents/viga/obj/local/armeabi-v7a/objs/van/main.o -lgcc /home/pep/workspace/elm/src/agents/viga/obj/local/armeabi-v7a/libecom.so /home/pep/workspace/elm/src/agents/viga/obj/local/armeabi-v7a/libgnustl_shared.so -no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fPIE -pie -mthumb  -L/home/pep/tools/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib /home/pep/tools/crystax-ndk-10.3.2/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libsupc++.a -L/home/pep/tools/crystax-ndk-10.3.2/sources/crystax/empty /home/pep/tools/crystax-ndk-10.3.2/sources/crystax/libs/armeabi-v7a/thumb/libcrystax.so -lc -o /home/pep/workspace/elm/src/agents/viga/obj/local/armeabi-v7a/van
/home/pep/workspace/elm/src/agents/viga/jni/main.cpp:34: error: undefined reference to 'ros::init(int&, char**, std::string const&, unsigned int)'
collect2: error: ld returned 1 exit status

看起来这个库没有被链接,没有-l,而是AFAIK,这是使用LOCAL_STATIC_LIBRARIES正确包含的。我已经尝试将其列为libroscpp以及-lroscpp。这是Android.mk。

LOCAL_PATH := $(call my-dir)

MY_ELM_HOME := /home/pep/workspace/elm/src
MY_ELM_INCL := /home/pep/workspace/elm/src/includes
MY_ROS_HOME := /home/pep/tools/ros-android-ndk/roscpp_android/output/roscpp_android_ndk

MY_COMMONS_INCL := $(MY_ELM_HOME)/includes/commons
MY_COMMONS_LIBS := $(MY_ELM_HOME)/libs/commons/libs/armeabi-v7a
MY_ROS_INCL := $(MY_ROS_HOME)/include
MY_ROS_LIBS := $(MY_ROS_HOME)/lib

include $(CLEAR_VARS)
LOCAL_MODULE := mycom
LOCAL_SRC_FILES := $(MY_COMMONS_LIBS)/libecom.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := van
LOCAL_C_INCLUDES := $(MY_ELM_INCL)
LOCAL_C_INCLUDES += $(MY_ROS_INCL)
LOCAL_SRC_FILES := main.cpp
LOCAL_CPPFLAGS := -std=gnu++14
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_LDLIBS := -L$(MY_ROS_LIBS)
LOCAL_SHARED_LIBRARIES := mycom
LOCAL_STATIC_LIBRARIES := libroscpp
LOCAL_STATIC_LIBRARIES += libroscpp_serialization
LOCAL_STATIC_LIBRARIES += librosconsole
include $(BUILD_EXECUTABLE)

$(call import-module,boost/1.59.0)

我已尝试将-lroscpp与LOCAL_LDLIBS一起使用,但我收到一个错误并且说使用LOCAL_STATIC_LIBRARIES的消息。我确定路径对于静态库是正确的。

以下是libroscpp.a中的符号。

$ nm -Ca ./libroscpp.a | grep "ros::init"
... <snip>
00000001 T ros::init(int&, char**, std::string const&, unsigned int)
... <snip>

我也尝试重新排序libs,但无济于事。

思想?

1 个答案:

答案 0 :(得分:1)

包含静态库(* .a)有一个与共享库一样使用的PREBUILD_STATIC_LIBRARY,你需要像libecom.so一样制作模块