Protocol Buffers protoc missing input file

还是要看官方原版的说明才管用

https://developers.google.com/protocol-buffers/

https://developers.google.com/protocol-buffers/docs/cpptutorial

Compiling Your Protocol Buffers

Now that you have a .proto, the next thing you need to do is generate the classes you'll need to read and write AddressBook (and hence Person and PhoneNumber) messages. To do this, you need to run the protocol buffer compiler protoc on your .proto:

  1. If you haven't installed the compiler, download the package and follow the instructions in the README.
  2. Now run the compiler, specifying the source directory (where your application's source code lives – the current directory is used if you don't provide a value), the destination directory (where you want the generated code to go; often the same as $SRC_DIR), and the path to your .proto. In this case, you...:
protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/addressbook.proto

Because you want C++ classes, you use the --cpp_out option – similar options are provided for other supported languages.

This generates the following files in your specified destination directory:

  • addressbook.pb.h, the header which declares your generated classes.
  • addressbook.pb.cc, which contains the implementation of your classes.

测试案例 (windows)

protoc -I=C:\protoc-3.6.1-win32\include\google\protobuf --cpp_out=C:\protoc-3.6.1-win32\include\google\protobuf empty.proto

最后的文件名可以只写文件名

一次性编译多个文件

有说直接将文件名写成*.proto,但在windows下行不通,可以在同一行里面把所有文件写上

protoc -I=C:\protoc-3.6.1-win32\include\google\protobuf --cpp_out=C:\protoc-3.6.1-win32\include\google\protobuf empty.proto any.proto
 

猜你喜欢

转载自blog.csdn.net/u013701860/article/details/81461810