我尝试在goggle协议缓冲区源中打印函数地址。 (因为有太多的函数来自protocc生成的C ++代码中的MergePartialFromCodedStream,我想找到这个函数。)但是遇到了一个错误。来源如下。
bool InlineMergeFromCodedStream(io::CodedInputStream* input,
MessageLite* message) {
GOOGLE_LOG(INFO) << "func addr = " << message->MergePartialFromCodedStream;
// <-- error line
if (!message->MergePartialFromCodedStream(input)) return false;
if (!message->IsInitialized()) {
GOOGLE_LOG(ERROR) << InitializationErrorMessage("parse", *message);
return false;
}
return true;
}
错误信息如下:
make all-recursive
make[1]: Entering directory `/home/ckim/Neuro/py-faster-rcnn/protobuf-2.6.1'
Making all in .
make[2]: Entering directory `/home/ckim/Neuro/py-faster-rcnn/protobuf-2.6.1'
make[2]: Leaving directory `/home/ckim/Neuro/py-faster-rcnn/protobuf-2.6.1'
Making all in src
make[2]: Entering directory `/home/ckim/Neuro/py-faster-rcnn/protobuf-2.6.1/src'
depbase=`echo google/protobuf/message_lite.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/sh ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I.. -pthread -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -MT google/protobuf/message_lite.lo -MD -MP -MF $depbase.Tpo -c -o google/protobuf/message_lite.lo google/protobuf/message_lite.cc &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -pthread -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -MT google/protobuf/message_lite.lo -MD -MP -MF google/protobuf/.deps/message_lite.Tpo -c google/protobuf/message_lite.cc -fPIC -DPIC -o google/protobuf/.libs/message_lite.o
google/protobuf/message_lite.cc: In function 'bool google::protobuf::<unnamed>::InlineMergeFromCodedStream(google::protobuf::io::CodedInputStream*, google::protobuf::MessageLite*)':
google/protobuf/message_lite.cc:121: error: no match for 'operator<<' in 'google::protobuf::internal::LogMessage((google::protobuf::LogLevel)0u, ((const char*)"google/protobuf/message_lite.cc"), 121).google::protobuf::internal::LogMessage::operator<<(((const char*)"test")) << message->google::protobuf::MessageLite::MergePartialFromCodedStream'
./google/protobuf/stubs/common.h:652: note: candidates are: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(const std::string&)
./google/protobuf/stubs/common.h:653: note: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(const char*)
./google/protobuf/stubs/common.h:654: note: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(char)
./google/protobuf/stubs/common.h:655: note: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(int)
./google/protobuf/stubs/common.h:656: note: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(google::protobuf::uint)
./google/protobuf/stubs/common.h:657: note: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(long int)
./google/protobuf/stubs/common.h:658: note: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(long unsigned int)
./google/protobuf/stubs/common.h:659: note: google::protobuf::internal::LogMessage& google::protobuf::internal::LogMessage::operator<<(double)
make[2]: *** [google/protobuf/message_lite.lo] Error 1
make[2]: Leaving directory `/home/ckim/Neuro/py-faster-rcnn/protobuf-2.6.1/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ckim/Neuro/py-faster-rcnn/protobuf-2.6.1'
make: *** [all] Error 2
它抱怨error: no match for 'operator<<' in ..
,因为我将函数地址设置为<<
。我尝试在函数地址之前添加(unsigned int)
强制转换。然后我得到了
google/protobuf/message_lite.cc: In function 'bool google::protobuf::<unnamed>::InlineMergeFromCodedStream(google::protobuf::io::CodedInputStream*, google::protobuf::MessageLite*)':
google/protobuf/message_lite.cc:121: error: invalid use of member (did you forget the '&' ?)
如果我只输入一个数字而不是函数地址,则编译好。
GOOGLE_LOG在protobuf-2.6.1 / src / google / protobuf / stubs / common.h中定义,如下所示。
#define GOOGLE_LOG(LEVEL) \
::google::protobuf::internal::LogFinisher() = \
::google::protobuf::internal::LogMessage( \
::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__)