英文:
How does Go locate imported packages?
问题
我是新手学习Go语言,根据如何编写Go代码准备好了我的工作空间。
但是现在我对于go工具如何获取fmt、strings或者我自己的包的路径感到困惑。
在C语言中,我们通过-I提供头文件的路径,通过-L提供链接器的路径,但是在Go语言中,我们给出了两个路径GOHOME和GOPATH,而且这两个路径都是bin目录,没有指定包的路径。
英文:
I am new to Go, and I have prepared my work space according to the How to write go code
But now I am confused how go tool gets the path of packages like fmt, strings or my own packages.
As in C language we provide the path of header file by -I and linker path by -L but in Go we have given two paths GOHOME and GOPATH and both paths are of bin directories none of them specify the package path.
答案1
得分: 2
根据你提供的链接中所解释的,GOPATH(以及其他Go的位置)应该按照以下方式布局:一个用于编译库的"pkg"目录,以及一个用于库源代码的"src"目录。它们不仅仅是二进制文件目录。
英文:
As is explained in the article you linked, GOPATH (and other go locations) should be layed out with a "pkg" directory for compiled libraries, and a "src" directory for library sources. They are not just bin directories.
答案2
得分: 0
$GOPATH 是一个由冒号(在 Windows 上是分号)分隔的路径列表,用于存放 Go 工作区(具有 {bin,pkg,src} 结构)。当编译和链接你的程序时,Go 工具会自动在这些路径中查找包和源文件。
英文:
$GOPATH is a colon (or semicolon on Windows) separated list of paths to Go workspaces (with the {bin,pkg,src} structure). The go tools will automatically look for packages and source files in those paths when compiling and linking your programs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论