android - 使用 Android NDK 构建 Protocol Buffer 时出错

标签 android c++ android-ndk protocol-buffers

我尝试在 Android NDK(完整库)中构建 Protocol Buffer 库。 (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_staticprotobuf_staticprotobuf_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。

关于android - 使用 Android NDK 构建 Protocol Buffer 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15448755/

相关文章:

c++ - 在 C++ 中,在 For 循环中使用非递增变量是否可以接受?

android - 为 Android 构建 tesseract 时出错

android - 指向 stdio FILE 的指针出现编译器错误

android - 使用 native CocosDenshion、cocos2d-x 循环播放音效时,AudioFlinger 无法创建音轨,状态为 : -12 ,

android - 由 EditText 组成的自定义 ListAdapter 失去焦点调用两次

Android:单击相机中的图像并在对话框中显示图像

android - 我的 android 应用程序在 onclick 时没有关闭

c++ - 虚函数性能: one large class vs many smaller subclasses

android - ICS 上的 native 堆栈跟踪?

java - 一秒内多次扫描信标(Android-Java)