2

I am facing an issue while linking the protobuf library.

/tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x444): undefined reference to google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4a9): undefined reference to google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4c4): undefined reference to google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4de): undefined reference to google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x502): undefined reference to google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x53c): more undefined references togoogle::protobuf::internal::kEmptyString' follow /tmp/ccKgczB9.o:TickData.pb.cc:(.text$_ZN6google8protobuf8internal10WireFormat16VerifyUTF8StringEPKciNS2_9OperationE[__ZN6google8protobuf8internal10WireFormat16VerifyUTF8StringEPKciNS2_9OperationE]+0x1b): undefined reference to `google::protobuf::internal::WireFormat::VerifyUTF8StringFallback(char const*, int, google::protobuf::internal::WireFormat::Operation)' collect2: error: ld returned 1 exit status

Language Used: C++ Protobuf Version: 2.6.1

I have already tried stuff on below links but it doesnt work out:

Can't compile example from google protocol buffers

and

Undefined reference to google::protobuf::internal::empty_string_[abi:cxx11]

I am new to C++. I have also tried compiling the protobuf using -std=c++11 but still the same error.

Any pointers will be helpful.

Community
  • 1
  • 1
Abhishek
  • 271
  • 3
  • 6
  • Please show the compiler command-line you used. (My guess is that it is missing the `-lprotobuf` flag.) – Kenton Varda Apr 02 '16 at 22:21
  • g++ -g -L"/cygdrive/d/Softwares/protobuf-2.6.1/src/.libs" ../proto/TickData.pb.cc main.cpp -std=c++11 -lprotobuf – Abhishek Apr 04 '16 at 14:57

1 Answers1

0

I did figure out a way out.

I need to first use the -c option for g++ and generate the .o files. Then again separately will have to use the -o option to generate the executable.

As shown below:

g++ -c -L/cygdrive/d/Workspace/CPP/Practice/.libs/ ../proto/TickData.pb.cc main.cpp -std=c++11 -lprotobuf

g++ -g -Wall TickData.pb.o main.o -o MarketData.o -std=c++11 -lprotobuf

Abhishek
  • 271
  • 3
  • 6