Alex G.
Alex G.

Reputation: 2153

I can't run Go programs anymore

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.

Upvotes: 20

Views: 13224

Answers (1)

peterSO
peterSO

Reputation: 166925

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

Upvotes: 39

Related Questions