1. 程式人生 > >學習go語言碰到的問題:main redeclared in this block

學習go語言碰到的問題:main redeclared in this block

E:\goapp

是我的GOPATH目錄

分別建立了2個檔案:

hello.go

// hello
package main

import "fmt"

func main() {
	fmt.Println("Hello World! 你好,世界!")
}

sandbox.go

// sandbox
package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println("Welcome to the playground!")
	fmt.Println("The time is ", time.Now())
}

在liteide執行BR的時候報錯了:main redeclared in this block previous declaration at .\hello.go:6

解決方案:在分別建立兩個資料夾hello和sandbox,把檔案放進去,再次BR兩個檔案,就沒問題了。

原因是:同一個目錄下面不能有個多 package main