2013-03-16 56 views
4

我尝试在Android NDK(完整库)中构建协议缓冲区库。 (How to build protocol buffer by Android NDK)。 但是,当我执行ndk-build,我得到一个错误使用Android NDK构建协议缓冲区时出错

... 
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构建成功。

+0

不要忘记奖励赏金! (点击+50)在“接受”勾号下。 – Goz 2013-03-29 12:08:45

回答

2

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 /谷歌/的protobuf /株/ stringprintf.cc必须被包括在内。