Java 如何构建libprotobuf-lite.so

Java 如何构建libprotobuf-lite.so,java,android,c++,android-ndk,protocol-buffers,Java,Android,C++,Android Ndk,Protocol Buffers,我试图让Protobuf lib在Android中的Java和JNI层之间进行通信。我从中获得源代码指导。所以我在Jni>source\u目录中将其作为源文件添加。现在,如果我执行ndk build以生成。so文件,则会提示以下错误日志: [armeabi] SharedLibrary : libprotobuf-lite.so jni/src/google/protobuf/stubs/common.cc:201: error: undefined reference to 'google:

我试图让Protobuf lib在Android中的Java和JNI层之间进行通信。我从中获得源代码指导。所以我在Jni>source\u目录中将其作为源文件添加。现在,如果我执行ndk build以生成。so文件,则会提示以下错误日志:

[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
[armeabi]共享库:libprotobuf-lite.so
jni/src/google/protobuf/stubs/common.cc:201:错误:未定义对“google::protobuf::util::Status::ToString()const”的引用

jni/src/google/protobuf/stubs/common.cc:207:错误:对“google::protobuf::operatorProto buffer”的未定义引用生成的c/c++代码依赖于google的支持代码,该代码与Proto buffer编译器一起安装。这意味着您得到的所有c/c++都依赖于protobuf的支持代码,这就是为什么会出现链接错误的原因——显然,在生成共享对象时,您没有将google的proto buffer支持库与其他链接资源链接在一起

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

看起来他实际上是在试图构建支持库本身。@KentonVarda afaik,它需要lib(libprotobuf lite.so)来构建我们编写的与Protobuf相关的源代码。但由于我没有找到。所以我尝试自己构建文件。但是让我产生了lib。现在唯一的问题是,我的系统运行在V3.0.0上,所以proto file.h和.cc使用V3.0.0生成,但受支持。所以该文件有旧版本,即2.6.1。因此会出现不匹配。这里有什么建议吗@然后这里的解决方案应该足够简单:确保protobuf支持代码和protobuf编译器使用相同的protobuf版本。我建议删除您当前安装的protobuf版本,安装您希望使用的版本,并重新编译您的protobuf.so支持库链接的protobuf文件。事实上,您的系统使用了一个proto版本,而您显然还有另一个proto版本用于proto编译,这无疑是通往痛苦世界的必经之路;)@Shubh:您绝对不能将一个版本的标题与另一个版本中构建的库相结合——protobuf在库版本之间不提供任何ABI兼容性。@RannLifshitz,Kenton。谢谢,这是真的,所以我更新了V3.0.0的代码,并为android构建。所以现在我的系统和要构建的代码。所以文件有相同的版本。现在我面临着另一个问题。有什么建议吗?