Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protoc-gen-go: unable to determine Go import path for "simple.proto"

I have simple proto file with following content.

syntax="proto3";

package main;

message Person {
      string name = 1;
      int32 age = 2; 
}

I am trying to generate go code for it using protoc. I run:

protoc --go_out=. simple.proto

I receive following error:

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 and simple.proto is in the same folder. Both protoc and protoc-gen-go are defined in PATH enviroement.

like image 402
srbemr Avatar asked Sep 10 '25 17:09

srbemr


2 Answers

Protoc requires that the package be specified, then the solution is to add

option go_package = "./your-package-name";

to make your file looks like the following:

syntax="proto3";

package main;

option go_package = "./your-package-name";

message Person {
      string name = 1;
      int32 age = 2; 
}

then you can run the command e.g:

protoc -I src/ --go_out=src/ src/simple/simple.proto

where --go_out=src/ specifies where your file will be generated then the relative path to your proto file.

Note: Don't forget to prefix the option go_package with ./

like image 85
Oscar Gallardo Avatar answered Sep 12 '25 23:09

Oscar Gallardo


You forgot to linkedlist the file with it by adding:

option go_package = "./";

You need to linkedlist it first to make it work. It was same issues here

like image 21
Panji Tri Wahyudi Avatar answered Sep 13 '25 01:09

Panji Tri Wahyudi