去:本地进口非本地包 [英] Go: local import in non-local package
问题描述
我有以下文件结构:
。
├──bin
│└──hello
├──pkg
└──src
└──jacob.uk.com
├ ──问候语
│└──greeting.go
└──helloworld.go
5个目录,3个档案
使用以下GOPATH
/ Users / clarkj84 /桌面/ LearningGo
执行 / usr / local / go / bin / go install jacob.uk.com
在 src
文件夹中,我得到错误本地导入./greeting本地包
helloworld.go
:
package main;
导入./greeting
func main(){
}
当指定非本地包到 go install
。如果您希望本地导入工作,请先将工作目录更改为 src / jacob.uk.com
,然后执行 go install
(不指定包)。
当然,您提供的 helloworld.go
会得到一个编译错误:导入并未使用
。但是,一旦你使用了导入的 greeting
包中的东西,它应该会被编译。
但是你不应该使用local进口。相反,请写:
importjacob.uk.com/greeting
这样做,您将能够从任何地方编译/运行/安装它。
I have the following file structure:
.
├── bin
│ └── hello
├── pkg
└── src
└── jacob.uk.com
├── greeting
│ └── greeting.go
└── helloworld.go
5 directories, 3 files
With the following GOPATH
/Users/clarkj84/Desktop/LearningGo
Upon executing /usr/local/go/bin/go install jacob.uk.com
within the src
folder, I get the error local import "./greeting" in non-local package
helloworld.go
:
package main;
import "./greeting"
func main() {
}
You can't use local import when specifying a non-local package to go install
. If you want the local import to work, first change working directory to src/jacob.uk.com
then execute go install
(without specifying the package).
Of course having the helloworld.go
you provided you will get an compile error: imported and not used
. But once you use something from the imported greeting
package, it should compile.
But you shouldn't use local imports at all. Instead write:
import "jacob.uk.com/greeting"
And doing so you will be able to compile/run/install it from anywhere.
这篇关于去:本地进口非本地包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!