如何编译谷歌Protobuf命令行界面编译
How to compile Google Protobuf command line interface compile
我正在尝试原始解码protobuf二进制文件。我从源代码 https://github.com/google/protobuf 安装了谷歌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 编译器位于不同的库中,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的函数。
相关文章:
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 谷歌测试中的期望值存储在哪里
- 谷歌模拟和覆盖关键字
- 如何使用ESP8266向谷歌主页发送命令
- 更正 CMakeList.txt 用于谷歌测试的文件?
- 如何将GTest与CMake一起使用?遵循谷歌指南时的链接问题
- 在没有 API 的情况下使用谷歌翻译文本
- 重载运算符<<采用谷歌 C++ 风格
- 如何在谷歌模拟中匹配 C 样式数组
- 如何让谷歌测试正常运行。测试总是失败。(它不会编译)
- 谷歌测试编译错误 Os X:函数式转换从"int"到"internal::FloatingEq2Matcher"的模糊转换<float>
- 编译的谷歌协议缓冲区不工作(C++)
- 我无法编译谷歌测试,告诉链接器输入未使用(macOS)
- 如何编译谷歌Protobuf命令行界面编译
- 如何在Visual Studio 2013的C++项目中编译和链接谷歌测试,但使用NuGet Package Manag
- 交叉编译树莓派的谷歌v8库
- 谷歌模拟成员函数中的std::pair参数编译失败
- 谷歌测试ASSERT_EQ不编译
- 为什么谷歌测试编译,但不能看到我的项目来源
- 谷歌模拟编译错误(错误:"<函数名称>"不是一种类型)