Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main redeclared in this block #29881

Closed
fengpf opened this issue Jan 23, 2019 · 3 comments

Comments

@fengpf
Copy link

commented Jan 23, 2019

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

What did you see instead?

System details

go version go1.11.1 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/fpf/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/data/app/go"
GOPROXY=""
GORACE=""
GOROOT="/data/app/go/src/go1.11.1"
GOTMPDIR=""
GOTOOLDIR="/data/app/go/src/go1.11.1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
GOROOT/bin/go version: go version go1.11.1 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.11.1
uname -v: Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.5
BuildVersion:	17F77
lldb --version: lldb-902.0.79.7
  Swift-4.1
gdb --version: GNU gdb (GDB) 8.1.1

When i create new file named test.go in the src/cmd/compile, then i execute go run main.go test.go, i got err :
./test.go:3:6: main redeclared in this block
previous declaration at ./main.go:40:6

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2019

What is on line 3 of test.go and line 40 of main.go?

@fengpf

This comment has been minimized.

Copy link
Author

commented Jan 23, 2019

on line 3 of test.go: func main() {
println("hello")
}

on line 40 of main.go: func main() {
// disable timestamps for reproducible output
log.SetFlags(0)
log.SetPrefix("compile: ")

archInit, ok := archInits[objabi.GOARCH]
if !ok {
	fmt.Fprintf(os.Stderr, "compile: unknown architecture %q\n", objabi.GOARCH)
	os.Exit(2)
}

gc.Main(archInit)
gc.Exit(0)

}

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2019

You have two defined the function main in two different places. That is what the error message is telling you. This is not a bug.

If you have questions about how to use Go I encourage you to use a forum rather than the bug tracker. Please see https://golang.org/wiki/Questions. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.