英文:
Importing from directory in Windows
问题
我的GOPATH
是C:\src\go
,我有一个项目,其目录结构如下:
C:\src\go\src\project\
main.go
folder\
file1.go
file2.go
file3.go
其中file1.go, file2.go, file3.go
有一个包名,而main.go
有一个名为main的包名和main方法。在main.go
中,我做了以下操作:
import (
"fmt"
"./folder"
)
但是,当我在命令行中运行go run main.go
时,我收到一个错误消息,说函数未定义,因为包没有正确加载,实际上,对于包加载错误,我得到了以下错误信息:
.\main.go:5: imported and not used: "_/C_/src/go/src/project/folder"
可以看到,路径并不完全正确。有什么办法在Windows中进行这种导入吗?
英文:
My GOPATH
is C:\src\go
, and I have a project which has the following directory structure:
C:\src\go\src\project\
main.go
folder\
file1.go
file2.go
file3.go
Where file1.go, file2.go, file3.go
has one package name, and main.go
has package name of main and the main method. In main.go
I did something like this:
import (
"fmt"
"./folder"
)
But then, I run from command line go run main.go
and I get an error messages that the functions are undefined, because the package is not loaded correctly, in fact for the package load error I get:
.\main.go:5: imported and not used: "_/C_/src/go/src/project/folder"
where as can be seen the path is not quite correct. Any ideas how to do this import in Windows?
答案1
得分: 2
请提供您的Go源代码文件夹的完整导入路径,类似于以下形式:
import (
"fmt"
"project/folder"
)
我还强烈建议您重新组织您的GOPATH目录,以便更好地组织您的项目,并且可以更轻松地导入自己的项目。您可以参考这个链接了解更多信息:https://astaxie.gitbooks.io/build-web-application-with-golang/en/01.2.html
英文:
Include the full import path from your go source folder so something like this :
import(
"fmt"
"project/folder"
)
I also highly recommend you restructure your GOPATH directory for organisation purposes so you can find importing your own projects much easier. https://astaxie.gitbooks.io/build-web-application-with-golang/en/01.2.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论