【发布时间】:2019-12-13 11:44:19
【问题描述】:
旧标题:如何使用 nanopb 和 protobuf 将 nanopb/examples/simple/simple.proto 文件编译成 simple.h 和 simple.c
关于这个库:https://github.com/nanopb/nanopb
我的目标是遵循本教程:https://jpa.kapsi.fi/nanopb/docs/concepts.html 将 nanopb/examples/simple/simple.proto 转换为 .h 和 .c 源文件。我需要简单的说明才能在 Ubuntu 上执行此操作。我已经尝试了几天,但无法让它工作。
教程说要做的命令是:
protoc -omessage.pb message.proto
python ../generator/nanopb_generator.py message.pb
我克隆了 nanopb 存储库,cd 到 nanopb/examples/simple,然后在上面的命令中替换为 simple.proto 而不是 message.proto,我运行了以下命令: p>
protoc -osimple.pb simple.proto
它运行良好,生成了一个 simple.pb 文件。
然而,第二部分失败了。从 nanopb/examples/simple 文件夹内运行时,我得到:
$ python ../../generator/nanopb_generator.py simple.pb
********************************************************************
*** Failed to import the protocol definitions for generator. ***
*** You have to run 'make' in the nanopb/generator/proto folder. ***
********************************************************************
Traceback (most recent call last):
File "../../generator/nanopb_generator.py", line 39, in <module>
import proto.nanopb_pb2 as nanopb_pb2
File "/home/gabriels/GS/dev/Protocol_Buffers/Nanopb/source/nanopb/generator/proto/nanopb_pb2.py", line 11, in <module>
from google.protobuf import symbol_database as _symbol_database
ImportError: cannot import name symbol_database
运行make 什么都不做(说它已经完成了):
nanopb/generator/proto $ make
make: Nothing to be done for `all'.
请注意,我正在运行最新版本的 protoc,它是从源代码:https://github.com/protocolbuffers/protobuf 的 Google protobuf 存储库构建的。
我也在这里寻求 nanopb 的帮助,但无法弄清楚,我觉得这里缺少一些基本的东西,因为我知道的不够多:https://github.com/nanopb/nanopb/issues/417。感觉就像我在做一些应该很简单的事情,并且在我之前至少有 1448 多人已经完成了(nanopb 上的星星数量)。
【问题讨论】:
标签: c protocol-buffers protoc protobuf-c nanopb