GO异常 | runnerw.exe: CreateProcess failed with error 21

背景

今天创建了一个GO项目,写了几行代码

package chapter1

import "fmt"

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

运行后抛出如下异常:

runnerw.exe: CreateProcess failed with error 216: 
Process finished with exit code 216

解决方案

经过排查,原来是因为idea在模块包chapter1创建go文件的话,默认导包名称是用了模块名package chapter1 导致了和main函数名称不一致,在GO中,package main表示一个可独立执行的程序,每个 Go 应用程序都包含一个名为main的包,这里的main函数必须对应导入的包名是 package main
这里写图片描述

只需要把包名改成main即可解决问题

package main


import "fmt"

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

这里写图片描述

posted @ 2018-08-30 03:25  EvanLeung  阅读(245)  评论(0编辑  收藏  举报