I’m trying to compile a Go program made up of multiple modules, like so:
// main.go
package main
import "mst"
// do something interesting involving minimum spanning trees
// src/mst/kruskal.go
import "disjsets"
// Kruskal's algorithm follows
// src/disjsets/disjsets.go
// implements disjoint sets with union-find
Now, when I run either go run main.go or go build after export GOPATH=. in the directory containing both main.go and src, it prints
# disjsets
open src/disjsets/disjsets.go: No such file or directory
I don’t get this. The file is there as ls -l src/disjsets/disjsets.go confirms. How can this happen? Where should the disjsets.go file live if Go is to find it?
(Google Go 1.0.2)
I believe you should read, or re-read How to Write Go code
In short:
Set you GOPATH to somewhere and export it for good. Then put some package
blahinto directoryor
or
Import
blahinto other packages asor
or
The package in that directory will contain the package files. Say you have only one,
blah.go. Then its location would beIf the blah package source file is named, say
proj.goinstead, thenBut the import paths would be the same as in the previous case.