c++ - How to compile Google Protobuf command line interface compile -
i trying raw decode protobuf binary. installed google protobuf library source code https://github.com/google/protobuf able use command line decode raw protobuf binary using command protoc --decode_raw <encodedfile>
. want able programmatically using c++ library. similar following example in documentation.
however trying compile simple piece of code not work.
#include <iostream> #include <fstream> #include <string> #include <google/protobuf/compiler/command_line_interface.h> using namespace google::protobuf::compiler; using namespace std; int main(int argc, char* argv[]) { google::protobuf::compiler::commandlineinterface cli_; cerr << "compiled , run" << endl; }
compile command
c++ my_program.cc -o my_program -pthread -i/usr/local/include -pthread -l/usr/local/lib -lprotobuf -lpthread
i see following error
my_program.cc:(.text+0x24): undefined reference `google::protobuf::compiler::commandlineinterface::commandlineinterface()' my_program.cc:(.text+0x4f): undefined reference `google::protobuf::compiler::commandlineinterface::~commandlineinterface()' my_program.cc:(.text+0x70): undefined reference `google::protobuf::compiler::commandlineinterface::~commandlineinterface()'
appreciate this.
protobuf compiler in different library, libprotoc
. need link against it
c++ my_program.cc -o my_program -pthread -i/usr/local/include -pthread -l/usr/local/lib -lprotoc -lprotobuf -lpthread
note -lprotoc
needs appear before -lprotobuf
, because libprotoc uses functions of libprotobuf.
Comments
Post a Comment