Building Protocol Buffers with go build

283 views
Skip to first unread message

doherty...@gmail.com

unread,
Feb 24, 2015, 8:15:25 PM2/24/15
to golan...@googlegroups.com
I am trying to build packages using an existing set of protos that my company has and have run into some issues. I have simplified the issue I am getting to the following workspace. Could someone please give me insight into what I am doing wrong or the appropriate documentation or venue to get help. Thank you and sorry if this is a simple question. 

patrick$ echo $GOPATH
/Users/patrick/Code/workspace

patrick$ pwd
/Users/patrick/Code/workspace

patrick$ cat src/foo/foo.proto
package foo;

message Foo
{
  optional string foo = 1;
}

patrick$ cat src/bar/bar.proto
package bar;

import "foo/foo.proto";

message Bar
{
  optional foo.Foo foo = 1;
  optional string bar = 2;
}

patrick$ protoc --go_out=src --proto_path=src/ src/foo/foo.proto
patrick$ protoc --go_out=src --proto_path=src/ src/bar/bar.proto
patrick$ go install foo
patrick$ go build bar
src/bar/bar.pb.go:18:8: cannot find package "foo/foo.pb" in any of:
        /usr/local/Cellar/go/1.3/libexec/src/pkg/foo/foo.pb (from $GOROOT)
        /Users/patrick/Code/workspace/src/foo/foo.pb (from $GOPATH)

Andrew Gwozdziewycz

unread,
Feb 25, 2015, 4:38:01 PM2/25/15
to golan...@googlegroups.com, doherty...@gmail.com


On Tuesday, February 24, 2015 at 8:15:25 PM UTC-5, doherty...@gmail.com wrote:
patrick$ protoc --go_out=src --proto_path=src/ src/foo/foo.proto
patrick$ protoc --go_out=src --proto_path=src/ src/bar/bar.proto
patrick$ go install foo
patrick$ go build bar
src/bar/bar.pb.go:18:8: cannot find package "foo/foo.pb" in any of:
        /usr/local/Cellar/go/1.3/libexec/src/pkg/foo/foo.pb (from $GOROOT)
        /Users/patrick/Code/workspace/src/foo/foo.pb (from $GOPATH)

Call me silly (I've never used protoc with go), but is this just a file name problem? You're using .proto, and it seems to be looking for .pb ?

 

doherty...@gmail.com

unread,
Feb 25, 2015, 5:12:06 PM2/25/15
to golan...@googlegroups.com, doherty...@gmail.com
protoc generates src/foo/foo.pb.go and src/bar/bar.pb.go so I do not believe that is the issue.

Jason E. Aten

unread,
Feb 25, 2015, 5:42:53 PM2/25/15
to golan...@googlegroups.com, doherty...@gmail.com
it looks you generated a package "foo", but then you're trying to import a different package, "foo/foo.pb"

doherty...@gmail.com

unread,
Feb 26, 2015, 9:54:01 PM2/26/15
to golan...@googlegroups.com, doherty...@gmail.com
Yes. When I change the import path for foo in bar.pb.go to import foo I can get the bar package to compile. Do you know how to get protoc to generate the correct import path?
Reply all
Reply to author
Forward
0 new messages