Trying to build Go definitions for github.com/tensorflow/tensorflow (off the r1.15.0 tag, if it matters):
protoc
-I./github.com/tensorflow/tensorflow
--go_out=plugins=grpc:./
./github.com/tensorflow/tensorflow/tensorflow/core/framework/*.proto
protoc
-I./github.com/tensorflow/tensorflow
--go_out=plugins=grpc:./
./github.com/tensorflow/tensorflow/tensorflow/core/protobuf/{saver,saved_model,struct,trackable_object_graph,saved_object_graph,meta_graph}.proto
gives the error:
2019/11/07 14:43:01 protoc-gen-go: error:inconsistent package import paths: "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf", "tensorflow/core/protobuf"
If I try using loads of M
arguments, the error goes away, but I get files written both to github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf
and tensorflow/core/protobuf
.
protoc -I./github.com/tensorflow/tensorflow --go_out=plugins=grpc,Mtensorflow/core/protobuf/saved_object_graph.proto=github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf,Mtensorflow/core/protobuf/struct.proto=github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf,Mtensorflow/core/protobuf/trackable_object_graph.proto=github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf:./ ./github.com/tensorflow/tensorflow/tensorflow/core/protobuf/{saver,saved_model,struct,trackable_object_graph,saved_object_graph,meta_graph}.proto
That leads to a Go compilation failure:
src/github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf/meta_graph.pb.go:54:24: undefined: SavedObjectGraph
That type was written to the tensorflow/core/protobuf/saved_object_graph.pb.go
file with an import back into github.com/tensorflow/tensorflow/tensorflow/go/core/framework
.
If I add a go_package
to these three files, everything is emitted into github.com/tensorflow/tensorflow/tensorflow/go/core
.
- tensorflow/core/protobuf/saved_object_graph.proto
- tensorflow/core/protobuf/struct.proto
- tensorflow/core/protobuf/trackable_object_graph.proto
option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf";
My question is: What is the recommended way to generate all the Go files into one package hierarchy? Should I need to modify the source? I’m unclear if there is a problem with my protoc
command, with proto-gen-go
, or with the TensorFlow code.
У меня есть простой прото-файл со следующим содержимым.
syntax="proto3";
package main;
message Person {
string name = 1;
int32 age = 2;
}
Я пытаюсь сгенерировать код для него, используя протокол. Я бегу:
protoc --go_out=. simple.proto
Я получаю следующую ошибку:
protoc-gen-go: unable to determine Go import path for "simple.proto"
Please specify either:
• a "go_package" option in the .proto source file, or
• a "M" argument on the command line.
main.go
, go.mod
и simple.proto
находятся в одной папке. И protoc
, и protoc-gen-go
определены в среде PATH.
3 ответа
Лучший ответ
Вам не хватает option go_package.
Имя, которое вы дадите option go_package
, будет именем пакета, который будет сгенерирован протоколом. Поступая таким образом, вы можете импортировать таким образом доступ к полям сообщений.
1
blockByblock
5 Янв 2022 в 06:19
Вы забыли связать файл с ним, добавив:
option go_package = "./";
Вам нужно сначала добавить его в список ссылок, чтобы он работал. Здесь были те же проблемы
0
Panji Tri Wahyudi
5 Янв 2022 в 04:18
Сначала убедитесь, что вы правильно установили компилятор
sudo apt install protobuf-compiler
sudo apt install golang-goprotobuf-dev
Используйте эту команду
protoc -I=src/ --go_out=src/ src/simple.proto
-I=IPATH -Указать директорию, в которой искать импорт
—go_out= выходной каталог
0
sk shahriar ahmed raka
5 Янв 2022 в 04:55
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
Topic: Errors I encountered when working with gRPC (Part 1)
Introduce
I am a newbie working with gRPC. The experiences are almost zero. This is the series of articles I will write about the errors I encountered when I started learning about gRPC. Hopefully other new friends like me if having the same error can save time.
Content
1. Error writing generate code from .proto file
When I generate the client/server stubs file, use the protoc command as follows:
protoc —go_out=. —go_opt=paths=source_relative —go—grpc_out=. —go—grpc_opt=paths=source_relative ecommerce/product_info.proto |
The last line is the path of the proto file we want to generate code from. Flag “go_out” yourself to “.” The purpose is for the generated code to be in the directory with the proto file. Above, I used more flags –go_opt=paths=source_relative ie when the code is generated, we can import the package of this code in the main.go file according to the path declared above. Here I use source_relative, it will implicitly be the path of the .proto file. After running the above command, I get the following error:
protoc-gen-go: unable to determine Go import path for "ecommerce/product_info.proto"
What is the cause? As we have worked with golang, Gopath is extremely important to determine the path of packages. Here we can use go.mod to be able to work in any directory outside of Gopath. The above error means that when we generate code from the product_info.proto file, we need to import some more packages or dependencies of the file to be imported to generate the file. So it needs to determine our Gopath in the local machine.
Fix to add paragraph
option go_package = "Your Gopath";
Go to the .proto file and you’re done.
After generating the code successfully, you may encounter a package could not import error in the newly generated .go file, you will fix it by calling “go get name_package”.
Kết Luận
Ok finished an error today. This is a very basic error but it will take a lot of time if it is a golang and gRPC fuzzy chicken like me. Wish you all good study