【问题标题】:NDK. Protobuf library linkingNDK。 Protobuf 库链接
【发布时间】:2012-09-16 06:29:46
【问题描述】:

美好的一天。我用 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)

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

【问题讨论】:

  • 尝试将LOCAL_LDLIBS := -lprotobuf 添加到Android.mk 并将其从LOCAL_SHARED_LIBRARIES 中删除
  • 顺便说一句,这里可能是错误的,但如果我没记错的话,LOCAL_SHARED_LIBRARIES 应该包含libprotobuf,而不是protobuf
  • 我认为库链接正确,因为如果我删除 LOCAL_SHARED_LIBRARIES 字符串,那么编译器会抛出更多错误
  • LOCAL_SHARED_LIBRARIES 可能是 protobuf 或 libprotobuf:NDK 都可以理解

标签: android c++ gcc android-ndk protocol-buffers


【解决方案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

【讨论】:

  • 就是这样!非常感谢!
  • 请您接受答案以便结束问题吗?
  • 链接已损坏。请复制答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-05
  • 2015-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-01
相关资源
最近更新 更多