登录
首页 >  Golang >  Go问答

在 Windows Server 2008 上出现“不是有效的 Win32 应用程序”错误

来源:stackoverflow

时间:2024-03-03 13:57:26 183浏览 收藏

一分耕耘,一分收获!既然打开了这篇文章《在 Windows Server 2008 上出现“不是有效的 Win32 应用程序”错误》,就坚持看下去吧!文中内容包含等等知识点...希望你能在阅读本文后,能真真实实学到知识或者帮你解决心中的疑惑,也欢迎大佬或者新人朋友们多留言评论,多给建议!谢谢!

问题内容

我遇到以下问题。我有一个为每个操作系统和 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

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

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:

内部链接的 Windows 二进制文件指定的 Windows 版本现在是 Windows 7 而不是 NT 4.0。这已经是 Go 所需的最低版本,但可能会影响具有向后兼容模式的系统调用的行为。这些现在将按照记录的方式运行。外部链接的二进制文件(任何使用 cgo 的程序)始终指定更新的 Windows 版本。

Windows 7 已发布版本 NT 6.1,Windows Server 2008 已发布版本 NT 6.0 (source)。因此,Windows Server 2008 不满足构建的二进制文件所需的最低 Windows 版本。

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

到这里,我们也就讲完了《在 Windows Server 2008 上出现“不是有效的 Win32 应用程序”错误》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>