go build fails on local packages resolving to underscore prefixed paths

487 views
Skip to first unread message

xbig...@gmail.com

unread,
Sep 14, 2015, 6:24:11 PM9/14/15
to golang-nuts
I work on a project with the following structure, and have been developing it for months without any problem.

project/
    module1
/
        module1
.go
    module2
/
        module2
.go
        submodule1
/
            submodule1
.go
        submodule2
/
            submodule2
.go
    module3
/
        module3
.go

As of today, when I execute `go build ./...` at the top of the project the following errors result.

module3/module3.go:98: undefined: submodule2.FunctionInSubmodule2

The code in question resembles the following.

package module3

import "github.com/company/project/module2/submodule2"

func
Execute() {
    err
:= submodule2.FunctionInSubmodule2()
   
if err != nil{
        panic
(err)
   
}
}

The only change I noticed starting today was the output from go build.

Previously, the package names were listed during the build, but now I am seeing them as paths in my home directory. These paths are also prefixed with underscores.

$ go build ./...
# _/home/myuser/myworkspace/project/source/backend/sundor
module3/module3.go:98: undefined: submodule2.FunctionInSubmodule2

Note that `/home/myuser/myworkspace/project` in a symlink to `$GOPATH/src/github.com/company/project`

I am running go 1.5.1 on Ubuntu 14.04.

I don't remember ever seeing the underscores in my imports before. Is this an issue anyone else has encountered. Any suggestions are appreciated.

Dave Cheney

unread,
Sep 14, 2015, 6:38:23 PM9/14/15
to golang-nuts
The go tool thinks GOPATH is not set or is incorrect. You must not use symlinks inside or around your GOPATH as symlinks allow the source of a package to appear at multiple locations and the go tool will act to avoid that, leaving you in the situation you find.

xbig...@gmail.com

unread,
Sep 14, 2015, 6:44:18 PM9/14/15
to golang-nuts
Thank you so much! That was exactly the problem. When I cd into the directory explicitly (not the symlink), the build works as expected. Strange that I've been developing multiple projects this way since go 1.3 without any trouble. Thanks again.
Reply all
Reply to author
Forward
0 new messages