Two executable files inside one directory

How to maintain files inside one directory?

/src/…/farkhad/hiphop/:
hip.go
hop.go

hip.go

package main

func main() {
	print("hip")
}

hop.go

package main

func main() {
  print("hop")
}

If I run “go build”, I receive error:

user@LAPTOP-9HJ1RCO2 MINGW64 ~/go/src/github.com/farkhad/hiphop (master)
$ go build
# github.com/farkhad/hiphop
.\hop.go:3:6: main redeclared in this block
        previous declaration at .\hip.go:3:6

You can have multiple files in the same package, but you are not allowed to have the same function twice. You’ll need to rename one of the main functions to something else.

If though you want to have two different executables, you need to put them into different folders.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.