GoLand IDE未正确编译。如何设置正确的路径?
我正在尝试正确设置GoLand,以便能够与Go一起使用它 我正在尝试运行follow simpleHelloWorldgo项目GoLand IDE未正确编译。如何设置正确的路径?,go,compiler-errors,ide,goland,Go,Compiler Errors,Ide,Goland,我正在尝试正确设置GoLand,以便能够与Go一起使用它 我正在尝试运行follow simpleHelloWorldgo项目 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=/Us
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 OS,并使用Brew安装了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 当您确实要去构建某个东西时。go或go不是all something.go,它只构建/安装go包,为您提供一个可执行文件。您将需要运行该可执行文件 运行简单Golang程序最简单的方法就是使用go run something.go来运行go文件
只要正确设置了GOPATH,它就应该工作看起来您正在尝试运行非主包。具体来说,您应该使用
package main
而不是package HelloWorldProject
。在此之后,IDE不仅可以生成,还可以运行包。您可以尝试更改包名而不是main在配置中有一个选项可在生成后运行。我认为您没有设置它的配置。步骤:
1.跑
2.选择“编辑配置”
3.选中输出目录字段下方指定“生成后运行”的复选框。我不确定您遇到了什么问题-生成已成功执行(
编译已完成,退出代码为0
)。是否应将Hello
和2
打印到控制台??这是我第一次使用GoLangLooks,就像你在建造它一样。为了查看输出,您必须实际运行它。