This is the oddest problem I've ever encountered. I have my Go development environment set up on a Windows 2008 R2 virtual machine. I don't even restart it nor run Windows update.
Today I just realized that I can no longer run Go programs. I can successfully build and run unit tests with 'go test'. However, running any compiled Go program, (even hello world) causes a pop-up window titled 'Unsupported 16-bit application' to appear. The error message is as follows:
The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.
The result is the same regardless of what version of Go I use (x86/x64). Also note that I'm not using any IDE. I call go.exe to build/test from the command line.
I can't get my head around this since running 'go test' works just fine.
Any thoughts?
EDIT:
Here's the console output when I build and run the program:
build/run output
Interestingly, dumpbin suggests that indeed there's something wrong with the executable
C:\Program Files (x86)\Microsoft Visual Studio 11.0>dumpbin /headers
C:\Projects \GoPlayground\src\playground\playground.exe Microsoft (R)
COFF/PE Dumper Version 11.00.51106.1 Copyright (C) Microsoft
Corporation. All rights reserved.
Dump of file C:\Projects\GoPlayground\src\playground\playground.exe
File Type: LIBRARY
C:\Projects\GoPlayground\src\playground\playground.exe : warning
LNK4003: invali d library format; library ignored
C:\Projects\GoPlayground\src\playground\playground.exe : warning
LNK4048: Invali d format file; ignored
Summary
C:\Program Files (x86)\Microsoft Visual Studio 11.0>
And here's the full source code:
package playground
import "fmt"
import "playground/another"
func main() {
fmt.Println("Hello world!")
fmt.Println(another.Foobar(2))
}
-------------------
package another
func Foobar(i int) int {
return i + 1
}
EDIT2:
I've reinstalled Go twice with no effect.
To run a Go program (assuming you have installed Go on your system), you need to instruct the Go compiler to compile and run a program using go run command with the relative or absolute path of the Go program file.
To run a go program, create a file with an extension .go and write your golang code in that file. For example, we will create a file named helloworld.go and write the following code in it. Now open command prompt and navigate to the location of helloworld.go file.
Does Go have a runtime? Go does have an extensive library, called the runtime, that is part of every Go program. The runtime library implements garbage collection, concurrency, stack management, and other critical features of the Go language.
It is probably building dependencies. Try go install first to build your package and its dependencies. After that, go run should be much faster.
The Go Programming Language Specification
Program execution
A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively. The main package must have package name main and declare a function main that takes no arguments and returns no value.
func main() { … }
Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete.
Use package main
, not package playground
. For example,
playground.go
:
package main
import (
"fmt"
"playground/another"
)
func main() {
fmt.Println("Hello world!")
fmt.Println(another.Foobar(2))
}
playground/another.go
:
package another
func Foobar(i int) int {
return i + 1
}
Output:
Hello world! 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With