如何在cocos2d-x中包含libprotobuf.a

时间:2012-09-07 05:27:43

标签: android android-ndk protocol-buffers cocos2d-x android-ndk-r7

我需要在我的cocos2d-x android项目中使用google的protobuf。我在项目中包含标题和C ++文件。但是当我尝试通过NDK编译项目时,编译器会返回错误:

jni/../../Classes/PromowallLibrary/protocol.pb.cpp:55: error: undefined reference to 'google::protobuf::DescriptorPool::generated_pool()' jni/../../Classes/PromowallLibrary/protocol.pb.cpp:55: error: undefined reference to 'google::protobuf::DescriptorPool::FindFileByName(std::basic_string, std::allocator > const&) const' jni/../../Classes/PromowallLibrary/protocol.pb.cpp:56: error: undefined reference to 'google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)'

等等。我怎样才能指向-lprotobuf库?我试过了:
LOCAL_LDLIBS := -lprotobuf \
但这是行不通的

更新:
现在我尝试以这种方式做 - 我创建静态模块:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_SRC_FILES := libprotobuf.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_CPP_EXTENSION := .cpp \
            .cc

LOCAL_SRC_FILES := helloworld/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp \
                   ../../Classes/PromowallLibrary/protocol.pb.cc

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

LOCAL_STATIC_LIBRARIES := libprotobuf
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static

include $(BUILD_SHARED_LIBRARY)

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

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libprotobuf LOCAL_SRC_FILES := libprotobuf.a LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := game_shared LOCAL_MODULE_FILENAME := libgame LOCAL_CPP_EXTENSION := .cpp \ .cc LOCAL_SRC_FILES := helloworld/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp \ ../../Classes/PromowallLibrary/protocol.pb.cc LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ $(LOCAL_PATH) LOCAL_STATIC_LIBRARIES := libprotobuf LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static include $(BUILD_SHARED_LIBRARY) $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)
现在我遇到了这样的错误:

/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(common.o): incompatible target /home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(generated_message_util.o): incompatible target /home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(message_lite.o): incompatible target /home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(repeated_field.o): incompatible target /home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(wire_format_lite.o): incompatible target

0 个答案:

没有答案