【问题标题】:How to compile Google Protobuf command line interface compile如何编译 Google Protobuf 命令行界面编译
【发布时间】:2017-07-25 11:21:43
【问题描述】:

我正在尝试对 protobuf 二进制文件进行原始解码。我从源代码https://github.com/google/protobuf 安装了google protobuf 库 我可以使用命令行使用命令protoc --decode_raw <encodedfile> 解码原始的protobuf 二进制文件。我希望能够使用 c++ 库以编程方式执行此操作。类似于文档中的以下示例。

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()'

感谢任何帮助。

【问题讨论】:

  • 您是否构建了 protobuf 库?使用步骤here

标签: c++ protocol-buffers


【解决方案1】:

Protobuf 编译器位于不同的库中,libprotoc。你需要链接它

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

注意-lprotoc需要出现在-lprotobuf之前,因为libprotoc使用了libprotobuf的函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-11
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    相关资源
    最近更新 更多