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