使用Android NDK构建协议缓冲区时出错

我尝试在
Android NDK(完整的lib)中构建协议缓冲库. (
How to build protocol buffer by Android NDK).

但是当我执行ndk-build时,我收到一个错误

...
Compile++ thumb  : protobuf <= printer.cc
Compile++ thumb  : protobuf <= tokenizer.cc
Compile++ thumb  : protobuf <= zero_copy_stream_impl.cc
Compile++ thumb  : protobuf <= importer.cc
Compile++ thumb  : protobuf <= parser.cc
SharedLibrary  : libprotobuf.so
jni/src/google/protobuf/io/tokenizer.cc:928: error: undefined reference to 'google::protobuf::StringAppendF(std::string*, char const*, ...)'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi/libprotobuf.so] Error 1

这是源代码包含错误:

...
// Helper to append a Unicode code point to a string as UTF8, without bringing
// in any external dependencies.
static void AppendUTF8(uint32 code_point, string* output) {
  uint32 tmp = 0;
  int len = 0;
  if (code_point <= 0x7f) {
    tmp = code_point;
    len = 1;
  } else if (code_point <= 0x07ff) {
    tmp = 0x0000c080 |
        ((code_point & 0x07c0) << 2) |
        (code_point & 0x003f);
    len = 2;
  } else if (code_point <= 0xffff) {
    tmp = 0x00e08080 |
        ((code_point & 0xf000) << 4) |
        ((code_point & 0x0fc0) << 2) |
        (code_point & 0x003f);
    len = 3;
  } else if (code_point <= 0x1fffff) {
    tmp = 0xf0808080 |
        ((code_point & 0x1c0000) << 6) |
        ((code_point & 0x03f000) << 4) |
        ((code_point & 0x000fc0) << 2) |
        (code_point & 0x003f);
    len = 4;
  } else {
    // UTF-16 is only defined for code points up to 0x10FFFF, and UTF-8 is
    // normally only defined up to there as well.
    StringAppendF(output, "\\U%08x", code_point); //<---- This error string
    return;
  }
  tmp = ghtonl(tmp);
  output->append(reinterpret_cast<const char*>(&tmp) + sizeof(tmp) - len, len);
}
...

如果此行已注释掉,则会进行编译.如何解决这个问题呢?

PS:protobuf_lite_static,protobuf_static和protobuf_lite_shared成功构建.

最佳答案 StringAppendF – 此函数包含在src / google / protobuf / stubs / stringprintf.cc(protobuf-2.5.0)中.

看你Android.mk:

PROTOBUF_FULL_SRC_FILES := \
$(PROTOBUF_LITE_SRC_FILES) \
src/google/protobuf/stubs/strutil.cc \
src/google/protobuf/stubs/substitute.cc \
src/google/protobuf/stubs/stringprintf.cc \
...

必须包含src / google / protobuf / stubs / stringprintf.cc.

点赞