"not a valid Win32 Application" 在 Windows Server 2008 上构建时

"not a valid Win32 Application" when building on a Windows Server 2008

我有以下问题。我有一个简单的 Golang 应用程序,我为每个 OS 和 ARCH 构建。 OS 我的意思是:

和阿奇:

MAC OS X,Windows Server 2008+ 一切正常。但是当我尝试 运行 在 Windows Server 2008 SP2 上编译应用程序时遇到问题。我收到以下错误:

App.exe is not a valid Win32 application

并且在尝试从 PowerShell 运行 时:

The specified executable is not a valid application for this OS platform

我的申请差不多1:1到this

如果 link 将来无法使用,请使用以下代码:

package main

import (
    "fmt"
    "time"

    "github.com/pion/webrtc/v3"
    "github.com/pion/webrtc/v3/examples/internal/signal"
)

func main() {
    // Everything below is the Pion WebRTC API! Thanks for using it ❤️.

    // Prepare the configuration
    config := webrtc.Configuration{
        ICEServers: []webrtc.ICEServer{
            {
                URLs: []string{"stun:stun.l.google.com:19302"},
            },
        },
    }

    // Create a new RTCPeerConnection
    peerConnection, err := webrtc.NewPeerConnection(config)
    if err != nil {
        panic(err)
    }

    // Set the handler for ICE connection state
    // This will notify you when the peer has connected/disconnected
    peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
        fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
    })

    // Register data channel creation handling
    peerConnection.OnDataChannel(func(d *webrtc.DataChannel) {
        fmt.Printf("New DataChannel %s %d\n", d.Label(), d.ID())

        // Register channel opening handling
        d.OnOpen(func() {
            fmt.Printf("Data channel '%s'-'%d' open. Random messages will now be sent to any connected DataChannels every 5 seconds\n", d.Label(), d.ID())

            for range time.NewTicker(5 * time.Second).C {
                message := signal.RandSeq(15)
                fmt.Printf("Sending '%s'\n", message)

                // Send the message as text
                sendErr := d.SendText(message)
                if sendErr != nil {
                    panic(sendErr)
                }
            }
        })

        // Register text message handling
        d.OnMessage(func(msg webrtc.DataChannelMessage) {
            fmt.Printf("Message from DataChannel '%s': '%s'\n", d.Label(), string(msg.Data))
        })
    })

    // Wait for the offer to be pasted
    offer := webrtc.SessionDescription{}
    signal.Decode(signal.MustReadStdin(), &offer)

    // Set the remote SessionDescription
    err = peerConnection.SetRemoteDescription(offer)
    if err != nil {
        panic(err)
    }

    // Create an answer
    answer, err := peerConnection.CreateAnswer(nil)
    if err != nil {
        panic(err)
    }

    // Create channel that is blocked until ICE Gathering is complete
    gatherComplete := webrtc.GatheringCompletePromise(peerConnection)

    // Sets the LocalDescription, and starts our UDP listeners
    err = peerConnection.SetLocalDescription(answer)
    if err != nil {
        panic(err)
    }

    // Block until ICE Gathering is complete, disabling trickle ICE
    // we do this because we only can exchange one signaling message
    // in a production application you should exchange ICE Candidates via OnICECandidate
    <-gatherComplete

    // Output the answer in base64 so we can paste it in browser
    fmt.Println(signal.Encode(*peerConnection.LocalDescription()))

    // Block forever
    select {}
}

我正在使用 GO 1.14 并通过以下方式构建它:

我相信这是因为自从 Go 1.13 以来,内部链接 Windows 二进制文件指定的 Windows 版本现在是 Windows 7:

The Windows version specified by internally-linked Windows binaries is now Windows 7 rather than NT 4.0. This was already the minimum required version for Go, but can affect the behavior of system calls that have a backwards-compatibility mode. These will now behave as documented. Externally-linked binaries (any program using cgo) have always specified a more recent Windows version.

Windows 7 的发布版本为 NT 6.1,Windows Server 2008 的发布版本为 NT 6.0 (source)。所以简单地说 Windows Server 2008 不满足构建二进制文件所需的最低要求 Windows 版本。

如果您需要支持 Windows Server 2008,请尝试使用 Go 1.12 构建它。