Reputation: 17151
If I run go build -o bin/test ./scripts/test.go
I get an executable, but when I try to run it I get
Failed to execute process './bin/test'. Reason:
exec: Exec format error
The file './bin/test' is marked as an executable but could not be run by the operating system.
scripts/test.go
package scripts
import (
"fmt"
)
func main() {
fmt.Println("hello")
}
Upvotes: 0
Views: 998
Reputation: 8425
The documentation for the go build
command has the details about how this works.
Summary:
-o
will force the command to not discard the output, and save it to the specified fileSo basically what you're doing here is building a non-main package, which outputs outputs an object file, not an executable. Normally this is discarded, but due to using the -o
option you've forced it to output it to a file.
To get an actual executable, you just need to change the package name to main
(as noted by Steven Penny)
Upvotes: 1
Reputation: 1
Should be package main
:
package main
import "fmt"
func main() {
fmt.Println("hello")
}
https://tour.golang.org/welcome
Upvotes: 2