golang的helloworld以及nonmain package的troubleshooting

原文地址:golang的hello-world以及non-main package的trouble-shooting | 我心永恒

我的个人博客地址:我心永恒 | 欢迎来到我的小站

Goland下创建项目:

在Goland中执行这个方法报错了:

Error: Run after the build is not possible.
The 'main' file has the non-main package or does not contain the 'main' function

报错的意思是说,找不到你写的包并没有main函数。

其实呢,package不是IDE自动弹出的包,而是跟go文件名一样的。

GOROOT:Go 语言安装根目录的路径,也就是 GO 语言的安装路径。

GOPATH:若干工作区目录的路径,是我们自己定义的工作空间。

GOBIN:GO 程序生成的可执行文件(executable file)的路径。

不要把GOPATH设置成go的安装路径。

GOPATH是作为编译后二进制的存放目的地和import包时的搜索路径 (其实也是你的工作目录, 你可以在src下创建你自己的go源文件, 然后开始工作)。

原文地址:golang的hello-world以及non-main package的trouble-shooting | 我心永恒

我的个人博客地址:我心永恒 | 欢迎来到我的小站

原文地址:https://www.cnblogs.com/tuhooo/p/15779613.html