Cross Compile to Windows i686 from Ubuntu Machine

Greetings,

I am attempting to cross compile an application: https://github.com/safex/vote/blob/master/app/proposalservice.rs

A user wants to run this application from their 32 bit windows machine.

I have installed the target for i686-pc-windows-gnu and when I try to compile the binary, it is returning to me this error:

error: failed to run custom build command for `openssl-sys v0.6.7`
process didn't exit successfully: `vote/target/debug/build/openssl-sys-acba6f232e617d43/build-script-build` (exit code: 101)
--- stdout
cargo:rustc-link-lib=dylib=ssl32
cargo:rustc-link-lib=dylib=eay32
TARGET = Some("i686-pc-windows-gnu")
OPT_LEVEL = Some("0")
TARGET = Some("i686-pc-windows-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("i686-pc-windows-gnu")
TARGET = Some("i686-pc-windows-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CC_i686-pc-windows-gnu = None
CC_i686_pc_windows_gnu = None
TARGET_CC = None
CC = None
HOST = Some("x86_64-unknown-linux-gnu")
CROSS_COMPILE = None
TARGET = Some("i686-pc-windows-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_i686-pc-windows-gnu = None
CFLAGS_i686_pc_windows_gnu = None
TARGET_CFLAGS = None
CFLAGS = None
PROFILE = Some("debug")
running: "i686-w64-mingw32-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-m32" "-o" "vote/target/i686-pc-windows-gnu/debug/build/openssl-sys-5caadec7e6f1f6b8/out/src/openssl_shim.o" "-c" "src/openssl_shim.c"
cargo:warning=src/openssl_shim.c:1:26: fatal error: openssl/hmac.h: No such file or directory
cargo:warning=compilation terminated.
ExitStatus(ExitStatus(256))


command did not execute successfully, got: exit code: 1



--- stderr
thread 'main' panicked at 'explicit panic', .cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.43/src/lib.rs:1127
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Normally this would resolve with installing openssl; however, it is installed. Not sure what to do next here.

I have not used ubuntu in a long while, but I believe what you need do depends on how you installed i686-w64-mingw32-gcc. Essentially, you need a version of openssl library also compiled with i686-w64-mingw32-gcc, so that your cross compiled version can link to it.

In other linux distros I've used more recently I would solve this by adding specific packages (openssl-dev) with an i686-w64-mingw32-gcc architecture, as opposed to linux x32 or x64 - I don't know how to do this in ubuntu though, maybe it will be necessary to manually compile openssl to link to?

1 Like

The easiest way to cross compile an application for Windows is to not cross compile at all, but just build it natively on Windows using a service like Appveyor (which has a free plan for open source).

2 Likes

Thanks @retep998, that's good advice especially going forward.

Thank @daboross for your reply as well.

1 Like