【问题标题】:compile protobuf client code on ubuntu, but include file is not found在 ubuntu 上编译 protobuf 客户端代码,但找不到包含文件
【发布时间】:2017-01-11 15:41:23
【问题描述】:

我刚刚在我的 ubuntu1604 上安装了 google 协议缓冲区:

sudo apt install protobuf-compiler

并尝试了快速测试,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;
}

我尝试编译,找不到包含文件:

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.

【问题讨论】:

    标签: c++ linux compilation include protocol-buffers


    【解决方案1】:

    您没有安装相关的 protobuf 头文件和库,它们独立于 protobuf 编译器。跑: sudo apt install libprotobuf-dev

    【讨论】:

    • 虽然这段代码 sn-p 可以解决问题,包括说明 如何为什么 这解决了问题 would really help 以改进你的帖子质量。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人!请edit您的答案添加解释,并说明适用的限制和假设。
    • 这个丢失的包是我需要的。谢谢!
    • 这也是“google/protobuf/any.proto:找不到文件”的解决方案。在 ubuntu 上编译 python protobuf 时。发表评论以帮助其他人找到此答案。
    猜你喜欢
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多