Compiling Golang Applications under Wine

I am trying to create an unprocessed (and possibly deterministic) build process for an application written in Go.

The idea is to create a Docker file that sets all the necessary conditions so that it can share the build process with others and does not require a real installation of Windows.

However, I was stuck trying to create a library with C bindings.

I get this very non descriptive error

C:\godev\src\github.com\obscuren\secp256k1-go>go build --work
WORK=C:\users\root\Temp\go-build287695705
# _/C_/godev/src/github.com/obscuren/secp256k1-go
copying $WORK\_\C_\godev\src\github.com\obscuren\secp256k1-go\_obj\_cgo_defun.8 to $WORK\_\C_\godev\src\github.com\obscuren\secp256k1-go.a: write $WORK\_\C_\godev\src\github.com\obscuren\secp256k1-go.a: Access denied.

The full log with -x can be found here .

I can build this library on OS X and a “real” Windows installation is just fine.

Any help would be appreciated.

Edit:

Using the OneofOne outline also gives me some errors.

# runtime/cgo
pkg/runtime/cgo/cgo.go:26:46: fatal error: sys/types.h: No such file or directory.
compilation terminated.

- Go. , gcc-multilib. .

# runtime/cgo
gcc: error: unrecognized command line option ‘-mthreads’

Google , . , - .

2:

, ,

apt-get install gcc-multilib
apt-get install gcc-mingw-w64

GOOS=windows GOARCH=386 CGO_ENABLED=1 CXX_FOR_TARGET=i686-w64-mingw32-g++ CC_FOR_TARGET=i686-w64-mingw32-gcc ./make.bash

.:)

+4
1

, - mingw64 Linux - Windows, , .

crosscompiling Go:

┌─ oneofone@Oa [~]                                                                                                               
└──➜ cd $GOROOT/src
┌─ oneofone@Oa [/u/s/g/src]                                                                                                      
└──➜ env GOOS=windows GOARCH=386 CGO_ENABLED=1 ./make.bash #use GOARCH=amd64 for 64bit windows binaries
....compile progress...
┌─ oneofone@Oa [/u/s/g/src]                                                                                                      
└──➜ cd /tmp

┌─ oneofone@Oa [/tmp]                                                                                                            
└──➜ cat win-cgo-test.go 
package main

/*
#include <stdlib.h>
#include <stdio.h>
*/
import "C"
import "unsafe"

func main() {
        hello := C.CString("Hello world")
        defer C.free(unsafe.Pointer(hello))
        C.puts(hello)
}

mingw Arch Linux:

/etc/pacman.conf:

[mingw-w64]
SigLevel = Never
Server = http://downloads.sourceforge.net/project/mingw-w64-archlinux/$arch
Server = http://arch.linuxx.org/archlinux/$repo/os/$arch

pacman -Syu mingw-w64-toolchain mingw-w64

: , 64- , multilib gcc, ArchLinux, pacman -Sy multilib-devel.

, , - mingw.

Windows, :

┌─ oneofone@Oa [/tmp]                                                                                                            
└──➜ env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ CGO_LDFLAGS="-lssp" go build win-cgo-test.go 
┌─ oneofone@Oa [/tmp]                                                                                                            
└──➜ file win-cgo-test.exe 
win-cgo-test.exe: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows

, https://github.com/OneOfOne/etc-fish/blob/master/env/01-go.fish.

Fish, , Bash ( - ).

//,

DLL ( 99% , 1%):

└──➜ i686-w64-mingw32-objdump -p win-cgo-test.exe | grep "DLL Name:"
        DLL Name: ws2_32.dll
        DLL Name: advapi32.dll
        DLL Name: ntdll.dll
        DLL Name: kernel32.dll
        DLL Name: winmm.dll
        DLL Name: msvcrt.dll
+4

All Articles