问题1:编译go程序失败?

go故障排查集锦_解决方法

Error: Run after the build is not possible

The 'main' file has the non-main package or does not contain the 'main' function

go故障排查集锦_解决方法_02

 

 10:52 Error running 'go build test1.go': Cannot run program "C:\Users\chalon\AppData\Local\Temp\GoLand\___go_build_test1_go.exe" (in directory "C:\Users\chalon\GolandProjects\go_test1"): CreateProcess error=216, 该版本的 %1 与你运行的 Windows 版本不兼容。请查看计算机的系统信息,然后联系软件发布者。

原因分析:没有main包;

解决方法:声明为main包即可。

go故障排查集锦_解决方法_03

 

 问题2:编译go程序失败?

10:59 Error running 'go build test1.go': Cannot run program "C:\Users\chalon\AppData\Local\Temp\GoLand\___go_build_test1_go.exe" (in directory "C:\Users\chalon\GolandProjects\go_test1"): CreateProcess error=5, 拒绝访问。

原因分析:go程序编译成功,但不能访问执行。

解决方法:执行受阻,设置安全规则即可。

go故障排查集锦_解决方法_04

 

问题3:无法编译go程序?

F:\>go run build test1.go
package build is not in GOROOT (C:\Program Files\Go\src\build)

F:\>go build test1.go
test1.go:1:1: expected 'package', found 'import'

原因分析:没有声明package;

解决方法:声明package即可。

 

问题4:无法编译go程序?

go故障排查集锦_软件发布_05

F:\>go build test1.go
# command-line-arguments
.test1.go:5:1: syntax error: non-declaration statement outside function body

原因分析:go程序中main()必须声明或调用。

解决方法:添加main()函数。

package main

import "fmt" 

func main(){
	fmt.Println("hello world!")
}

go故障排查集锦_不兼容_06go故障排查集锦_ide_07