我试图正确地设置GoLand,以便能够与Go一起使用它。
我正在尝试运行以下简单的HelloWorld go项目。
package HelloWorldProject
import "fmt"
func main(){
fmt.Printf("Hello")
fmt.Printf("1+1 = ", 1+1)
}
这是我的控制台的结果:
GOROOT=/usr/local/Cellar/go/1.10/libexec #gosetup
GOPATH=/Users/jeanmac/go #gosetup
/usr/local/Cellar/go/1.10/libexec/bin/go build -i -o /private/var/folders/r5/rfwd1cqd4kv8cmh5gh_qxpvm0000gn/T/___Hello /Users/jeanmac/go/src/github.com/jpere547/HelloWorldProject/Hello.go #gosetup
Compilation finished with exit code 0
我在Mac上,我安装了Go使用啤酒。
brew info go
结果
go: stable 1.10 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://golang.org
/usr/local/Cellar/go/1.10 (8,150 files, 336.9MB) *
Poured from bottle on 2018-03-22 at 19:38:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb
==> Requirements
Required: macOS >= 10.8 ✔
==> Options
--without-cgo
Build without cgo (also disables race detector)
--without-race
Build without race detector
--HEAD
Install HEAD version
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:/usr/local/opt/go/libexec/bin
GoLand配置如下:
GOROOT
GOPATH
发布于 2018-03-23 18:51:40
当您需要构建something.go或go时,只有构建/安装go包才能为您提供一个可执行文件的something.go。您将需要运行该可执行文件。
运行简单Golang程序的最简单方法是使用go运行something.go,它将运行go文件。
只要你的GOPATH设置正确,它就能工作
发布于 2018-03-24 00:53:19
看起来您正在尝试运行一个非主包。具体来说,您应该使用package HelloWorldProject
而不是package main
。在此之后,IDE将不仅能够构建而且能够运行包。
发布于 2018-08-03 03:40:57
您可以尝试更改包名而不是main。
https://stackoverflow.com/questions/49454780
复制相似问题