Reputation: 1231
Does anyone know if it's possible to use the "go build" command to build from multiple files in a directory? For example
src/
file1.go
file2.go
Where file1.go contains the "func main()" method and file2 provides supporting functions. I've tried by using the following import statements but I'm getting no where
import (
"file2"
)
import (
file2 "./file2"
)
I'm wondering if this is a case that I need to modify the GOROOT environment variable to get this to work. Or if I'm just being daft and missing something blindingly obvious.
Thanks
Upvotes: 3
Views: 452
Reputation: 24547
If file1.go and file2.go are part of the same package, this should work fine. You don't have to import files from the same package into each other. Their variables and functions are already shared.
If the files belong to different packages, they should be in different directories.
Upvotes: 5