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

Can't cross compile from Linux to Windows (x86_64) #32858

Closed
bozaro opened this issue Apr 9, 2016 · 5 comments
Closed

Can't cross compile from Linux to Windows (x86_64) #32858

bozaro opened this issue Apr 9, 2016 · 5 comments

Comments

@bozaro
Copy link

bozaro commented Apr 9, 2016

Environment:

  • Ubuntu 16.04 LTS final beta (lxc-create -n rust -t ubuntu -- --release xenial)
  • Mingw (apt install mingw-w64)
  • rustup tool (curl https://sh.rustup.rs -sSf | sh)
  • Rust 1.8 and nightly (rustup default beta/rustup default nightly)
  • Rust windows x86_64 toolchain (rustup target add x86_64-pc-windows-gnu)

I create a sample file hello.rs:

fn main() {
    println!("Hello, world!");
}

And run compilation:

rustc -v -C linker=x86_64-w64-mingw32-ld --target x86_64-pc-windows-gnu hello.rs

I expected hello.exe file, but has error:

error: linking with `x86_64-w64-mingw32-ld` failed: exit code: 1
note: "x86_64-w64-mingw32-ld" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/crt2.o" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "hello.0.o" "-o" "hello.exe" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-18402db3.rlib" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcollections-18402db3.rlib" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_unicode-18402db3.rlib" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librand-18402db3.rlib" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc-18402db3.rlib" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc_system-18402db3.rlib" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-18402db3.rlib" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-18402db3.rlib" "-l" "gcc_eh" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-l" "advapi32" "-l" "compiler-rt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "/home/ubuntu/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsend.o"
note: x86_64-w64-mingw32-ld: unrecognised emulation mode: 64
Supported emulations: i386pep i386pe

error: aborting due to previous error
@bozaro
Copy link
Author

bozaro commented Apr 9, 2016

Same issue with Ubuntu 14.04.4 LTS

@alexcrichton
Copy link
Member

Right now the linker specified with -C linker is actually expected to look like gcc, so if you pass x86_64-w64-mingw32-gcc, does it work?

@bozaro
Copy link
Author

bozaro commented Apr 9, 2016

rustc -v -C linker=x86_64-w64-mingw32-gcc --target x86_64-pc-windows-gnu hello.rs

Works correctlly.

@bozaro bozaro closed this as completed Apr 9, 2016
@L-as
Copy link

L-as commented Aug 5, 2018

Will this ever be fixed? It doesn't make sense to use gcc as the linker...

@TheRadioGuy
Copy link

@laaas +1

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

4 participants