1

再会。我用 ndk 编译了 protobuf 2.4.1 库。我从那篇文章中获取的脚本: How to build protocol buffer by Android NDK

但是当我尝试将我的库链接到测试 cocos2d-x 项目时,我得到了下一个错误:

SharedLibrary  : libgame.so
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::RegistrationRequest const* google::protobuf::internal::dynamic_cast_if_available<promowall::RegistrationRequest const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::RegistrationResponse const* google::protobuf::internal::dynamic_cast_if_available<promowall::RegistrationResponse const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::InstallIntentRequest const* google::protobuf::internal::dynamic_cast_if_available<promowall::InstallIntentRequest const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::ItemRequest const* google::protobuf::internal::dynamic_cast_if_available<promowall::ItemRequest const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o: In function `promowall::ItemResponse const* google::protobuf::internal::dynamic_cast_if_available<promowall::ItemResponse const*, google::protobuf::Message const*>(google::protobuf::Message const*)':
/usr/include/google/protobuf/generated_message_reflection.h:396: undefined reference to `typeinfo for google::protobuf::Message'
./obj/local/armeabi/objs-debug/game_shared/__/__/Classes/protocol.pb.o:/usr/include/google/protobuf/generated_message_reflection.h:396: more undefined references to `typeinfo for google::protobuf::Message' follow
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libgame.so] Error 1

正如我从这个日志编译器中看到的,找不到消息类型。但是源文件 message.cc 和 message_lite.cc 包含在 libprotobuf.so 库中。下面列出了我的测试应用程序 Android.mk 的源代码

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := protobuf
LOCAL_MODULE_FILENAME := libprotobuf
LOCAL_SRC_FILES := libprotobuf.so

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := game_shared

LOCAL_MODULE_FILENAME := libgame

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp \
              ../../Classes/protocol.pb.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

LOCAL_SHARED_LIBRARIES := protobuf

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)

我将非常感谢任何帮助:)

4

1 回答 1

1

您的日志表明您没有打开 RTTI 支持。有关说明,请参阅https://developer.android.com/ndk/guides/cpp-support#rtti

要在 ndk-build 中跨整个应用程序启用 RTTI,请将以下行添加到Application.mk文件中:

APP_CPPFLAGS := -frtti

要为单个 ndk-build 模块启用 RTTI,请将以下行添加到其Android.mk中的给定模块:

LOCAL_CPP_FEATURES := rtti

或者,您可以使用:

LOCAL_CPPFLAGS := -frtti
于 2012-09-16T15:48:07.237 回答