GCC 3.4编译Google Protocol Buffer 2.4.0a

gcc 3.4是比较老的编译器,用它来编译最新版protobuf 2.4.0a的话,可能会有如下错误:

google/protobuf/descriptor.cc: In member function `virtual const google::protobuf::FieldDescriptor* google::protobuf::DescriptorBuilder::OptionInterpreter::AggregateOptionFinder::FindExtension(google::protobuf::Message*, const std::string&) const':
./google/protobuf/descriptor.h:1152: error: `google::protobuf::internal::Mutex*google::protobuf::DescriptorPool::mutex_' is private
google/protobuf/descriptor.cc:4341: error: within this context
./google/protobuf/descriptor.h:1152: error: `google::protobuf::internal::Mutex*google::protobuf::DescriptorPool::mutex_' is private
google/protobuf/descriptor.cc:4342: error: within this context
make[2]: *** [descriptor.lo] Error 1
make[2]: Leaving directory `/home/liangry/download/protobuf-2.4.0a/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/liangry/download/protobuf-2.4.0a'
make: *** [all] Error 2

需打上以下补丁:
  1. --- ./src/google/protobuf/descriptor.cc 2011-02-02 22:08:47.000000000 +0800  
  2. +++ ./src/google/protobuf/descriptor.cc 2011-04-07 10:35:29.000000000 +0800  
  3. @@ -2160,6 +2160,11 @@  
  4.    static inline bool get_is_placeholder(const Descriptor* descriptor) {  
  5.      return descriptor->is_placeholder_;  
  6.    }  
  7. +  static inline void assert_mutex_held(const DescriptorPool* pool) {  
  8. +    if (pool->mutex_ != NULL) {  
  9. +      pool->mutex_->AssertHeld();  
  10. +    }  
  11. +  }  
  12.    // Must be run only after options have been interpreted.   
  13.    //   
  14. @@ -4338,9 +4343,12 @@  
  15.    virtual const FieldDescriptor* FindExtension(  
  16.        Message* message, const string& name) const {  
  17. +    /* 
  18.      if (builder_->pool_->mutex_ != NULL) { 
  19.        builder_->pool_->mutex_->AssertHeld(); 
  20.      } 
  21. +    */  
  22. +    assert_mutex_held(builder_->pool_);  
  23.      Symbol result = builder_->LookupSymbolNoPlaceholder(  
  24.          name, message->GetDescriptor()->full_name());  
  25.      if (result.type == Symbol::FIELD &&  
在protobuf-2.4.0a编译目录下,把上述内容保存为protobuf_gcc3.4.patch,然后输入以下命令即可。
$ patch -p0 < protobuf_gcc3.4.patch
patching file ./src/google/protobuf/descriptor.cc