Poco C ++ for Android链接问题

时间:2014-07-31 03:08:51

标签: android c++ eclipse android-ndk poco

我正在尝试通过NDK将Poco C ++(PocoFoundation和PocoNet)用于我的Android应用程序。我在eclipse上构建项目时遇到了这些问题:

[armeabi] Compile++ thumb: MySharedLib <= wrapper.cpp
[armeabi] SharedLibrary  : libMySharedLib.so
src/IPAddress.cpp:127: error: undefined reference to 'Poco::NumberFormatter::append(std::string&, int)'
src/IPAddress.cpp:129: error: undefined reference to 'Poco::NumberFormatter::append(std::string&, int)'
src/IPAddress.cpp:131: error: undefined reference to 'Poco::NumberFormatter::append(std::string&, int)'
src/IPAddress.cpp:133: error: undefined reference to 'Poco::NumberFormatter::append(std::string&, int)'
src/SocketAddress.cpp:413: error: undefined reference to 'Poco::NumberParser::tryParseUnsigned(std::string const&, unsigned int&)'
collect2: error: ld returned 1 exit status

这是我的Application.mk:

NDK_TOOLCHAIN_VERSION := 4.8
APP_ABI := armeabi
APP_STL := gnustl_shared
APP_CPPFLAGS += -std=c++11 -pthread -frtti -fexceptions

和Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := sodium
LOCAL_SRC_FILES := prebuild/libsodium.a
LOCAL_EXPORT_C_INCLUDES := include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := PocoFoundation
LOCAL_SRC_FILES := prebuild/libPocoFoundation.a
LOCAL_EXPORT_C_INCLUDES := include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := PocoNet
LOCAL_SRC_FILES := prebuild/libPocoNet.a
LOCAL_EXPORT_C_INCLUDES := include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := MyStaticLib
LOCAL_SRC_FILES := prebuild/libMyStaticLib.a
LOCAL_EXPORT_C_INCLUDES := include
LOCAL_STATIC_LIBRARIES := sodium PocoFoundation PocoNet
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := MySharedLib
LOCAL_SRC_FILES := wrapper.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include 
LOCAL_LDLIBS := -ldl -llog
LOCAL_STATIC_LIBRARIES := MyStaticLib
include $(BUILD_SHARED_LIBRARY)

Poco静态库是使用独立工具链构建的,如此链接http://pocoproject.org/docs/99300-AndroidPlatformNotes.html#2

任何人都可以帮我解决这些问题吗?谢谢。

1 个答案:

答案 0 :(得分:2)

我找到了链接问题的原因。对于Android.mk中的PocoNet静态库配置,我们需要添加LOCAL_STATIC_LIBRARIES:= PocoFoundation,因为PocoNet依赖于PocoFoundation。我现在的PocoNet部分Android.mk如下:

include $(CLEAR_VARS)
LOCAL_MODULE := PocoNet
LOCAL_SRC_FILES := prebuild/libPocoNet.a
LOCAL_EXPORT_C_INCLUDES := include
LOCAL_STATIC_LIBRARIES:= PocoFoundation
include $(PREBUILT_STATIC_LIBRARY)