代码之家  ›  专栏  ›  技术社区  ›  CoDe

如何构建libprotobuf-lite.so

  •  1
  • CoDe  · 技术社区  · 10 年前

    我正在尝试让Protobuf-lib在Android中的Java和JNI层之间进行通信。我从 here 。所以我在Jni>中添加了此作为源文件;源目录。现在如果我表演 ndk构建 生成 所以 文件,则会提示以下错误日志:

    [armeabi] SharedLibrary  : libprotobuf-lite.so
    jni/src/google/protobuf/stubs/common.cc:201: error: undefined reference to 'google::protobuf::util::Status::ToString() const'
    jni/src/google/protobuf/stubs/common.cc:207: error: undefined reference to 'google::protobuf::operator<<(std::ostream&, google::protobuf::uint128 const&)'
    jni/src/google/protobuf/arena.h:622: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
    jni/src/google/protobuf/arena.h:624: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
    jni/src/google/protobuf/arena.h:462: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
    jni/src/google/protobuf/arena.h:617: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
    jni/src/google/protobuf/arena.h:617: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
    jni/src/google/protobuf/arena.h:617: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
    jni/src/google/protobuf/arena.h:633: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
    jni/src/google/protobuf/arena.h:624: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
    jni/src/google/protobuf/wire_format_lite.cc:514: error: undefined reference to 'google::protobuf::internal::IsStructurallyValidUTF8(char const*, int)'
    jni/src/google/protobuf/wire_format_lite.cc:527: error: undefined reference to 'google::protobuf::StringPrintf(char const*, ...)'
    collect2: error: ld returned 1 exit status
    

    如果我遗漏了什么,有什么建议吗?

    1 回复  |  直到 10 年前
        1
  •  2
  •   Rann Lifshitz rul    10 年前

    Proto缓冲区生成的c/c++代码依赖于谷歌的支持代码,该代码与Proto缓冲编译器一起安装。这意味着你得到的所有c/c++都依赖于protobuf的支持代码,这就是为什么你会出现链接错误的原因——显然,在生成共享对象时,你没有将谷歌的protobuffer支持库与其他链接资源链接在一起。

    我为JNI.so库创建了一个eclipse构建,在其中我向链接器添加了-lprotobuf标志,如图所示 here (搜索makefile,然后滚动到Linker部分)。 希望这能帮上忙。