# go env | grep GOPATH
GOPATH="/home/hiller/gocode"
#cd /home/hiller/gocode/src/test2
# cat test.go
package main
import (
"fmt"
"test2"
)
func main() {
fmt.Println("Hello, World!")
test2()
}
------------------------------------
# cat test2.go
package test2
import "fmt"
func test2() {
fmt.Println("Hello, hiller!")
}
----------------------------------------
# go run test.go
test.go:5:2: found packages main (test.go) and test2 (test2.go) in /home/hiller/gocode/src/test2
請大佬幫忙看看,多謝。
uj5u.com熱心網友回復:
把test2.go放入src/test2檔案夾下簡單地理解,package就代表檔案夾,除了main package,go源檔案都要放入對應的package的檔案夾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/192943.html
標籤:go語言
上一篇:救救孩子,看看哪里錯了
下一篇:python 3.9.0安裝問題
