我尝试在 Android NDK(完整库)中构建协议缓冲区库。(如何通过 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
成功。