如何在 Android.mk 中包含静态第三方库?
How to include a static third party lib within Android.mk?
我正在尝试使用 Android.mk 在静态库中 link,但出现以下错误。
/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
看起来库没有被 link 编辑,没有 -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>
我也试过重新排序库,但无济于事。
想法?
为了包含静态库 (*.a),有一个 PREBUILD_STATIC_LIBRARY 像共享库一样使用,也就是说你需要像 libecom.so
一样制作模块
我正在尝试使用 Android.mk 在静态库中 link,但出现以下错误。
/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
看起来库没有被 link 编辑,没有 -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>
我也试过重新排序库,但无济于事。
想法?
为了包含静态库 (*.a),有一个 PREBUILD_STATIC_LIBRARY 像共享库一样使用,也就是说你需要像 libecom.so
一样制作模块