2017-07-25 7 views
0

私はprotobufバイナリを生デコードしようとしています。 https://github.com/google/protobuf 私は、コマンドprotoc --decode_raw <encodedfile>を使って、protobufバイナリをデコードするためにコマンドラインを使用することができます。私はこれをプログラムでC++ライブラリを使ってやりたいと思っています。ドキュメントの次の例に似た何か。GoogleのProtobufコマンドラインインターフェイスをコンパイルする方法

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

しかし、コードのシンプルな作品が動作しませんコンパイルしようとしています。

#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 And Run" << endl; 

} 

c++ my_program.cc -o my_program -pthread -I/usr/local/include -pthread -L/usr/local/lib -lprotobuf -lpthread 

コマンドをコンパイルし、私は次のエラー

my_program.cc:(.text+0x24): undefined reference to `google::protobuf::compiler::CommandLineInterface::CommandLineInterface()' 
my_program.cc:(.text+0x4f): undefined reference to `google::protobuf::compiler::CommandLineInterface::~CommandLineInterface()' 
my_program.cc:(.text+0x70): undefined reference to `google::protobuf::compiler::CommandLineInterface::~CommandLineInterface()' 

はこれで任意の助けに感謝ご覧ください。

+0

protobufライブラリを作成しましたか? [ここ](https://github.com/google/protobuf/tree/master/src)の手順を使用してください。 – Steeve

答えて

1

Protobufコンパイラは別のライブラリlibprotocにあります。あなたはlibprotocがlibprotobufの機能を使用するため-lprotocは、-lprotobuf前に表示する必要があることを注意

c++ my_program.cc -o my_program -pthread -I/usr/local/include -pthread -L/usr/local/lib -lprotoc -lprotobuf -lpthread 

それをリンクする必要があります。

関連する問題