Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross compiling for Windows #10

Closed
mikong opened this issue Apr 14, 2019 · 1 comment
Closed

Cross compiling for Windows #10

mikong opened this issue Apr 14, 2019 · 1 comment

Comments

@mikong
Copy link
Owner

mikong commented Apr 14, 2019

Environment: x86_64-apple-darwin
Target: x86_64-pc-windows-gnu

Note: Our target is x86_64-pc-windows-gnu instead of x86_64-pc-windows-msvc. The MSVC ABI is only needed if we want to interoperate with software produced by Visual Studio. It also requires Visual Studio or Visual C++ Build Tools.

We encounter the following error messages as described in rust-lang/rust#48272:

undefined reference to `__onexitend'
undefined reference to `__onexitbegin'

That issue in rust-lang/rust was closed after they added back the downloading of rust-mingw, but it doesn't help our case. We have our own MinGW and removing the linker from ~/.cargo/config will result in a linker error as described in rust-lang/rust#33465:

ld: unknown option: --enable-long-section-names
clang: error: linker command failed with exit code 1

To Reproduce

  1. Install MinGW:
$ brew install mingw-w64
# Installs 6.0.0 as of writing
  1. Install cross compiled standard library:
$ rustup target add x86_64-pc-windows-gnu
  1. Update ~/.cargo/config:
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
  1. Cross compile with cargo:
$ cargo build --target=x86_64-pc-windows-gnu
$ cargo build --release --target=x86_64-pc-windows-gnu
@mikong
Copy link
Owner Author

mikong commented Apr 14, 2019

For now, we can follow the solution described in one of the comments in rust-lang/rust#48272 (comment):

$ cd ~/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-pc-windows-gnu/lib/
$ cp crt2.o crt2.o.bak
$ cp /usr/local/Cellar/mingw-w64/6.0.0/toolchain-x86_64/x86_64-w64-mingw32/lib/crt2.o .

@mikong mikong closed this as completed Apr 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant