相关疑难解决方法(0)

在ubuntu上编译protobuf客户端代码,但是找不到包含文件

我刚刚在我的 ubuntu1604 上安装了 google protocol buffer:

sudo apt install protobuf-compiler
Run Code Online (Sandbox Code Playgroud)

并尝试了一个快速测试,1个proto文件,1个cpp文件来使用它,尝试查看编码/解码结果:

$ cat 1.proto
package x;
message my{
required string name=1;
required int32 id=2;
optional string email=3;
}

$ cat 1.cpp
#include"1.pb.cc"
#include<string>
#include<iostream>
using namespace std;
using namespace x;
int main()
{
  my p;
  p.set_name("tom");
  p.set_id(18);
  p.set_email("aa@bb.com");
  string s;
  my.SerializeToString(&s);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我试图编译它,未能找到包含文件:

protoc 1.proto --cpp_out=./
g++ 1.cpp 1.pb.cc -lprotobuf

In file included from 1.pb.cc:5:0,
             from 1.cpp:1:
1.pb.h:9:42: fatal error: google/protobuf/stubs/common.h: No such file or directory
compilation terminated. …
Run Code Online (Sandbox Code Playgroud)

c++ linux compilation include protocol-buffers

3
推荐指数
1
解决办法
1803
查看次数

标签 统计

c++ ×1

compilation ×1

include ×1

linux ×1

protocol-buffers ×1