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.

https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.command_line_interface

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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -