【问题标题】:importing google/protobuf/*.protos when using protoc-c使用 protoc-c 时导入 google/protobuf/*.protos
【发布时间】:2019-07-29 17:59:01
【问题描述】:

我在我的系统上安装了 protoc、protoc-c、libprotobuf 和 libprotobuf-c。我有导入 timestamp.proto 的 .proto 文件,如下所示:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message DeviceCtx {

    google.protobuf.Timestamp CID = 1;

    uint32 ContextLen = 2;

    bytes ContextBuf = 3;

}

我正在使用 protoc-c 为相同的内容生成 C 绑定:

home>protoc-c --c_out=. a.proto
home>ls a.pb-c*
a.pb-c.c a.pb-c.h

它为这个 proto 文件生成 C 绑定。但是当我尝试编译这个 .c 文件时,我得到了以下错误,因为它正在寻找 timestamp.pb-c.h 文件。

home>gcc a.pb-c.c dummy.c -I/usr/local/include -L/usr/local/lib -lprotobuf-c
In file included from a.pb-c.c:9:0:
a.pb-c.h:17:10: fatal error: google/protobuf/timestamp.pb-c.h: No such file or directory
#include "google/protobuf/timestamp.pb-c.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

使用 protoc-c 在安装 protoc-c 时,我看不到标准 proto 的头文件(如 timestamp.proto)正在生成/暂存。这是否意味着我们必须使用 protoc-c 显式重新编译 google/protobuf 下的所有 protos 来为所有 protos (google/protobuf/*.protos) 生成 C 绑定,将生成的头文件暂存到 /usr/local/include 下/google/protobuf 并在我们的库中包含 *pb-cc 文件使它能够成功构建?我是否需要安装任何特定的包来获取 google/protobuf 下的 protos 的 C 绑定。我是否错过了安装过程中的某个步骤,这会为 google/protobuf 下的所有 protos 自动生成 C 绑定并正确上演。

如果我不从 google/protobuf 导入任何原型,我看不到任何问题。

当对同一个 proto 文件使用 protoc 时,我没有看到任何此类问题。

home>protoc --cpp_out=. a.proto
home>g++ a.pb.cc dummy.cc -I/usr/local/include -L/usr/local/lib -lprotobuf
home>

我是 protobuf 新手,第一次使用 protoc-c 编译器。所以为我的缺点道歉。

谢谢, -迷你

【问题讨论】:

    标签: protocol-buffers


    【解决方案1】:

    通常在 3rd 方 protobuf 库中,您会将 Google 的 .proto 文件视为与您自己编写的任何 .proto 相同。因此,您将编写规则以将它们编译到特定于项目的包含目录中的文件夹中。

    【讨论】:

      猜你喜欢
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      相关资源
      最近更新 更多