compile protobuf client code on ubuntu, but include file is not found

痴心易碎 提交于 2020-07-21 11:30:26

问题


I just installed google protocol buffer on my ubuntu1604:

sudo apt install protobuf-compiler

And tried a quick test, 1 proto file, 1 cpp file to use it, try to see the encode/decode results:

$ 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;
}

I tried to compile it, failed to find include files:

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.
In file included from 1.pb.cc:5:0:
1.pb.h:9:42: fatal error: google/protobuf/stubs/common.h: No such file or directory
compilation terminated.

回答1:


You did not install associated protobuf header and lib, which is independent from protobuf-compiler. Run: sudo apt install libprotobuf-dev



来源:https://stackoverflow.com/questions/41594991/compile-protobuf-client-code-on-ubuntu-but-include-file-is-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!