{{tag>Pb Go Wine windows}} # Pb compilation Go lang pour windows erreur avec wine ## Étapes à reproduire Source : https://d3ext.github.io/posts/malware-dev-0/ `main.go` ~~~go package main import ( "fmt" "unsafe" "golang.org/x/sys/windows" ) func main() { user32 := windows.NewLazyDLL("user32.dll") MessageBox := user32.NewProc("MessageBoxW") r, _, _ := MessageBox.Call( 0, uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("Hello World!"))), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("Example"))), windows.MB_OK, ) fmt.Println("Return code:", r) } ~~~ ~~~bash env GOARCH=amd64 GOOS=windows go build main.go ~~~ ## Erreur ~~~ $ wine main.exe it looks like wine32 is missing, you should install it. multiarch needs to be enabled first. as root, please execute "dpkg --add-architecture i386 && apt-get update && apt-get install wine32:i386" wine: created the configuration directory '/home/jibe/.wine' 0050:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002 0050:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002 0050:err:ole:apartment_get_local_server_stream Failed: 0x80004002 0050:err:ole:start_rpcss Failed to open RpcSs service 0048:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002 0048:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002 0048:err:ole:apartment_get_local_server_stream Failed: 0x80004002 wine: failed to open L"C:\\windows\\syswow64\\rundll32.exe": c0000135 wine: configuration in L"/home/jibe/.wine" has been updated. fatal error: bcryptprimitives.dll not found runtime: panic before malloc heap initialized runtime stack: runtime.throw({0x1400e5c03?, 0x21fd58?}) /usr/lib/go-1.26/src/runtime/panic.go:1229 +0x4d fp=0x21fca8 sp=0x21fc78 pc=0x140076fad runtime.loadOptionalSyscalls() /usr/lib/go-1.26/src/runtime/os_windows.go:267 +0x349 fp=0x21fd90 sp=0x21fca8 pc=0x140041229 runtime.osinit() /usr/lib/go-1.26/src/runtime/os_windows.go:464 +0x3d fp=0x21fe10 sp=0x21fd90 pc=0x14004193d runtime.rt0_go() /usr/lib/go-1.26/src/runtime/asm_amd64.s:372 +0x13e fp=0x21fe18 sp=0x21fe10 pc=0x14007b2be ~~~ ~~~ $ env WINEARCH=win64 wine main.exe wine: could not load kernel32.dll, status c0000135 $ mkdir -p ~/myapp/prefix $ env LANG=C WINEPREFIX=$HOME/myapp/prefix WINEARCH=win32 wine main.exe Application could not be started, or no application associated with the specified file. ShellExecuteEx failed: Bad EXE format for Z:\home\jibe\go\winapi\main.exe. ~~~ ## Solution Voir : * https://go.dev/wiki/Windows Utiliser une ancienne version de Go ou une recompilée pour être compatible avec windows 7 Comme : https://github.com/thongtech/go-legacy-win7 ~~~bash export GOROOT=~/opt/go-legacy-win7/ alias go='~/opt/go-legacy-win7/bin/go' go env |grep '/' rm -rf ~/.cache/go-build go clean -cache -modcache env GOARCH=amd64 GOOS=windows GOROOT=~/opt/go-legacy-win7/ ~/opt/go-legacy-win7/bin/go build main.go ~~~