在GO(GO1)中使用多个文件进行构建
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
有人知道是否可以使用“ go build”命令从目录中的多个文件进行构建吗? 例如 p>
src /
file1.go
file2.go
code> pre>
其中file1.go包含 “ func main()”方法和file2提供了支持功能。 我已经尝试过使用以下导入语句,但在哪里都找不到 p>
import(
“ file2”
)
import(
file2“ ./file2"
)
pre>
我想知道是否需要修改GOROOT环境变量才能使其正常工作。 或者,如果我只是愚蠢而错过了令人眼花obvious乱的明显事物。 p>
谢谢 p>
div>
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.