0
votes

I'm following the cpp tutorial on google protocol buffers

I installed Google Protocol Buffers on Ubuntu and compiled the .proto file so I got the pb.h and pb.cc generated files.

enter image description here

I made ReadAddressBook.cpp very minimal. It just creates the proto object and verifies if the version matches.

#include <iostream>
#include <fstream>
#include <string>
#include "address_book.pb.h"
using namespace std;

int main(){

 GOOGLE_PROTOBUF_VERIFY_VERSION;

 tutorial::AddressBook address_book;

return 0;
}

I compiled it with

g++ -c ReadAddressBook.cpp

(also with g++ -c ReadAddressBook.cpp -lprotobuf -lpthread but it gave the same results)

However when running:

g++ -o ReadAddressBook ReadAddressBook.o

enter image description here

It gave me the references to the google protobuf src was unavailable. Why would this be?

1
You should add address_book.pb.cc for compilation and linking. try this g++ ReadAddressBook.cpp address_book.pb.cc -lprotobuf -lpthread .lnman
@nomem Then when I compile after do I put g++ -c ReadAddressBook.cpp or g++ -c ReadAddressBook.cpp address_book.pb.cc? What would be the next steps?Jebathon
the command I gave would directly make the executable. If you want to compile then link then try this: g++ -c ReadAddressBook.cpp address_book.pb.cc and g++ -o ReadAddressBook ReadAddressBook.o address_book.pb.o -lprotobuf -lpthreadlnman

1 Answers

0
votes

You need to add -lprotobuf to the link phase, but it looks like you tried to use it in the compile phase. That is, you want to do:

g++ -c ReadAddressBook.cpp
g++ -o ReadAddressBook ReadAddressBook.o -lprotobuf -lpthread