在ubuntu上编译protobuf客户端代码,但是找不到包含文件 [英] compile protobuf client code on ubuntu, but include file is not found

查看:119
本文介绍了在ubuntu上编译protobuf客户端代码,但是找不到包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just installed google protocol buffer on my ubuntu1604:

sudo apt install protobuf-compiler

并尝试进行快速测试,使用1个原型文件,1个cpp文件,尝试查看编码/解码结果:

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.

推荐答案

您没有安装关联的protobuf标头和lib,它们独立于protobuf-compiler.跑: sudo apt install libprotobuf-dev

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

这篇关于在ubuntu上编译protobuf客户端代码,但是找不到包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆