Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何编译googleprotobuf命令行界面编译_C++_Protocol Buffers - Fatal编程技术网

C++ 如何编译googleprotobuf命令行界面编译

C++ 如何编译googleprotobuf命令行界面编译,c++,protocol-buffers,C++,Protocol Buffers,我正在尝试对protobuf二进制文件进行原始解码。我从源代码安装了GoogleProtobuf库 我能够使用命令行使用protoc-decode_raw命令对原始protobuf二进制文件进行解码。我希望能够使用C++库来编程。与文档中的以下示例类似 然而,试图编译一段简单的代码是行不通的 #include <iostream> #include <fstream> #include <string> #include <google/protobuf

我正在尝试对protobuf二进制文件进行原始解码。我从源代码安装了GoogleProtobuf库 我能够使用命令行使用protoc-decode_raw命令对原始protobuf二进制文件进行解码。我希望能够使用C++库来编程。与文档中的以下示例类似

然而,试图编译一段简单的代码是行不通的

#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;

}
我看到以下错误

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的函数。

您构建了protobuf libs吗?使用步骤。
c++  my_program.cc  -o my_program -pthread -I/usr/local/include  -pthread -L/usr/local/lib -lprotoc -lprotobuf -lpthread