Trying to build c-shared for Windows x86

Hi,

for my Uplink.Net.wrapper I would like to build the uplinkc-lib for x86 (32bit). It is working for 64bit with this command:
go build -o storj_uplink.dll -buildmode c-shared

If I now switch the go-env like this:
set CC=i686-w64-mingw32-gcc
set CXX=i686-w64-mingw32-g++
set GOARCH=386

I get the following build error:
build storj.io/storj/lib/uplinkc: cannot find module for path storj.io/storj/internal/errs2

Does anybody know what this means and what I can do?

Thank you!

Regards,

TopperDEL

^^ @Egon Maybe you can help?

Hi,

I can reproduce the problem, but I haven’t yet figured out what the cause is. It seems that there’s some interaction between modules, CGO and the custom arch. I need to debug the compiler to figure out what’s going on underneath.

Thanks for your reply!

Looking Forward Hearing from you on this! If I can help, let me know!

Ah, ok, figured it out.

For cross compiling the default value for CGO_ENABLED is 0, however for compiling on the same platform it’s 1. You will need to set CGO_ENABLED=1.

set CC=i686-w64-mingw32-gcc
set CXX=i686-w64-mingw32-g++
set GOARCH=386
set CGO_ENABLED=1

Relevant Go issue https://github.com/golang/go/issues/24068

3 Likes

This is interessting. It works if I set it - so Thank you very much!
The strange Thing is: if I start my command prompt and do a go env, I can see that this Parameter is set already. I had this one in view, but thaught “it’s set already, so it is ok”.

Nevertheless, I can build x86 now. Thank you!

In case anyone is interested: I also had to set some linker-flags so that the function names in the created DLL are not decorated with the amount of parameters the function has (like with a trailing @8):

set CGO_CFLAGS=-g -O2 -Wl,–kill-at
set CGO_CXXFLAGS=-g -O2 -Wl,–kill-at
set CGO_FFLAGS=-g -O2 -Wl,–kill-at
set CGO_LDFLAGS=-g -O2 -Wl,–kill-at

One can have a look at my build-script here.