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

标签 windows go windows-server-2008

我遇到以下问题。我有一个为每个操作系统和 ARCH 构建的简单 Golang 应用程序。我的意思是操作系统:

  • Windows(GOOS=Windows)
  • OSX(它是在 OSX 机器上构建的)

和拱门:

  • 32 (GOARCH=amd64)
  • 64 (GOARCH=386)

在 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

如果链接将来不起作用,请使用以下代码:

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 build -ldflags "-s -w"app.go
  • 我也尝试过 go build app.go 但它没有改变任何东西:(

最佳答案

我相信这是因为从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 构建它。

关于windows - 在 Windows Server 2008 上构建时为 "not a valid Win32 Application",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62681151/

相关文章:

windows - OpenACC 与 OpenMP

map - 使用接口(interface)动态映射 YAML 的更简单方法?

asp.net-mvc - 无法使 Web API 应用程序在 Windows 2008 服务器上工作

c++ - 如何查看系统是否处于注销状态?

windows - 如何在Windows中保护文件

go - Go程序中的三个后台goroutine是什么?

go - 如何将连接参数 db 传递给 main.go?

MySQL 远程托管在虚拟服务器上 - 无法从 Mac 连接

asp.net - 使用 IPv6 访问 Web 服务

c++ - 如何使用 C++ 中的源代码扩展 .lib?