【发布时间】: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