我正在尝试使用 boost 1-49 的序列化库编译一个 android 应用程序。具体来说,这个项目有一些方便的脚本来完成工作:https ://github.com/MysticTreeGames/Boost-for-Android
使用 gnu-libstdc++ 4.6 for armeabi-v7a,针对官方 ndk-r8 构建的 Boost 没有问题。
至少,它能够创建 libboost_serialization-gcc-mt-1_49.a 而不会遇到任何错误。在构建过程中引发了几个警告,'禁止零大小数组'_pad' [-pedantic]','不支持'long long','不允许命名可变参数宏',似乎没有什么严重的,但我没有' t 自称是 gnu 编译器方面的专家。
构建 boost 还创建了 libboost_wserialization-gcc-mt-1_49.a,这看起来很奇怪,但可能无关紧要。我没有将它包含在我的 makefile 中。
无论如何,当我现在尝试使用这个库编译我的代码时,我会收到以下错误:
/Users/wespaugh/Development/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libboost_serialization-gcc-mt-1_49.a(xml_iarchive.o): in function boost::archive::xml_iarchive_impl<boost::archive::xml_iarchive>::load(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&):./boost/archive/impl/xml_iarchive_impl.ipp:71: error: undefined reference to 'mbtowc'
/Users/wespaugh/Development/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libboost_serialization-gcc-mt-1_49.a(xml_iarchive.o): in function boost::archive::xml_iarchive_impl<boost::archive::xml_iarchive>::load(wchar_t*):./boost/archive/impl/xml_iarchive_impl.ipp:101: error: undefined reference to 'mbtowc'
/Users/wespaugh/Development/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libboost_serialization-gcc-mt-1_49.a(xml_iarchive.o): in function boost::archive::xml_iarchive_impl<boost::archive::naked_xml_iarchive>::load(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&):./boost/archive/impl/xml_iarchive_impl.ipp:71: error: undefined reference to 'mbtowc'
/Users/wespaugh/Development/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libboost_serialization-gcc-mt-1_49.a(xml_iarchive.o): in function boost::archive::xml_iarchive_impl<boost::archive::naked_xml_iarchive>::load(wchar_t*):./boost/archive/impl/xml_iarchive_impl.ipp:101: error: undefined reference to 'mbtowc'
/Users/wespaugh/Development/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/libboost_serialization-gcc-mt-1_49.a(xml_oarchive.o): in function boost::archive::iterators::ostream_iterator<char> std::__copy_move<false, false, std::input_iterator_tag>::__copy_m<boost::archive::iterators::mb_from_wchar<boost::archive::iterators::xml_escape<wchar_t const*> >, boost::archive::iterators::ostream_iterator<char> >(boost::archive::iterators::mb_from_wchar<boost::archive::iterators::xml_escape<wchar_t const*> >, boost::archive::iterators::mb_from_wchar<boost::archive::iterators::xml_escape<wchar_t const*> >, boost::archive::iterators::ostream_iterator<char>):./boost/archive/iterators/mb_from_wchar.hpp:91: error: undefined reference to 'wctomb'
collect2: ld returned 1 exit status
编辑
好的,我在午餐时间在这方面取得了一些进展。通过实际挖掘 boost 中的那些 src 文件,我发现 mbtowc 及其倒数是 gnu-libstdc++ 的一部分。因此,不知何故,当我构建 boost 时,它一定没有得到正确的参考。午餐时间不能再给它了,但我已经查看了 boost 是如何编译的,并且使用的标志应该适当地链接所有内容。
从构建日志:
Building with TOOLSET=gcc-androidR8 CXXPATH=/Users/wespaugh/Development/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ CXXFLAGS=-I/Users/wespaugh/Development/android-ndk-r8d/platforms/android-14/arch-arm/usr/include -I/Users/wespaugh/Development/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.6/include -I/Users/wespaugh/Development/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include
结束编辑
鉴于我在库中遇到错误,并且它是我在代码中使用的唯一库,我认为 makefile 不会有问题。不过,为了彻底起见,这里有以下内容:Android.mk,包含在我保存已编译的 boost 库的位置:
# define module to include serialization static library
LOCAL_PATH:= $(call my-dir)
# serialization
include $(CLEAR_VARS)
LOCAL_CFLAGS += -I$(LOCAL_PATH)/include/boost-1_49
# -L$(LOCAL_PATH)/lib/
LOCAL_LDLIBS += -lboost_serialization \
-L$(NDK_ROOT)/sources/cxx-stl/ gnu-libstdc++/4.6/libs/armeabi-v7a \
-lgnustl_static
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti
LOCAL_CPP_EXTENSION := .cpp .hpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/boost-1_49 \
$(LOCAL_PATH)/include/boost-1_49/boost/archive \
$(LOCAL_PATH)/include/boost-1_49/boost/serialization
LOCAL_MODULE:= boost_serialization
LOCAL_SRC_FILES:= lib/libboost_serialization-gcc-mt-1_49.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../Classes
include $(PREBUILT_STATIC_LIBRARY)
Android.mk,在 proj.android/jni/
# compile the app
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LDFLAGS= -L$(NDK_ROOT)/sources/crystax/libs/armeabi-v7a/4.6.3 -Lcrystax
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../../../cocos2dx/platform/third_party/android/prebuilt/libboost/include/boost-1_49 \
$(LOCAL_PATH)/../../../cocos2dx/platform/third_party/android/prebuilt/libboost/include/boost-1_49/boost/archive \
$(LOCAL_PATH)/../../../cocos2dx/platform/third_party/android/prebuilt/libboost/include/boost-1_49/boost/serialization
LOCAL_WHOLE_STATIC_LIBRARIES := boost_serialization cocos2dx_static cocosdenshion_static cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx)
$(call import-module,libboost)
我最好的猜测是我没有正确构建提升,但不能肯定地说。什么可能导致这些错误?我什至无法搜索据称在序列化库中引用的文件(“mbtowc”和排列)。它是否试图引用我没有通过 makefile 包含的系统或文件系统提升库?