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

Linker error on cross compile to x86_64-pc-windows-gnu #33465

Closed
Kimundi opened this issue May 6, 2016 · 10 comments
Closed

Linker error on cross compile to x86_64-pc-windows-gnu #33465

Kimundi opened this issue May 6, 2016 · 10 comments

Comments

@Kimundi
Copy link
Member

Kimundi commented May 6, 2016

Attempting to cross compile from 64Bit Arch after doing

rustup target add x86_64-pc-windows-gnu
cargo build --release --target=x86_64-pc-windows-gnu --verbose

Errors with an linker error:

marvin@tp-marvin-arch ~/d/r/g/fun1> cargo build --release --target=x86_64-pc-windows-gnu --verbose
       Fresh winapi v0.2.6
       [...]
       Fresh cgmath v0.9.1
   Compiling fun1 v0.1.0 (file:///home/marvin/dev/rust/graphics_fun_2016-05-05/fun1)
     Running `rustc src/main.rs --crate-name fun1 --crate-type bin -C opt-level=3 --out-dir /home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release --emit=dep-info,link --target x86_64-pc-windows-gnu -L dependency=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release -L dependency=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps --extern chrono=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libchrono-086951ef1dea2712.rlib --extern specs=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libspecs-5ca5e24705e76ffe.rlib --extern gfx_device_gl=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_device_gl-6f378e292a444005.rlib --extern glutin=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libglutin-fe8847f8e5c48a8d.rlib --extern cgmath=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libcgmath-76ab5db7eccfb351.rlib --extern gfx_window_glutin=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_window_glutin-d2f847aed3bc91f3.rlib --extern gfx=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx-dc2b98d25789486e.rlib -L native=/home/marvin/.cargo/registry/src/github.com-88ac128001ac3a9a/dwmapi-sys-0.1.0/x86_64`
error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/crt2.o" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/fun1.0.o" "-o" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/fun1.exe" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release" "-L" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps" "-L" "/home/marvin/.cargo/registry/src/github.com-88ac128001ac3a9a/dwmapi-sys-0.1.0/x86_64" "-L" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx-dc2b98d25789486e.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libcgmath-76ab5db7eccfb351.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_window_glutin-d2f847aed3bc91f3.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libglutin-fe8847f8e5c48a8d.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libdwmapi-57add9827d7809cf.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libuser32-f952491ba4e166ee.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libshared_library-8a12fcda5e4d258b.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/liblazy_static-5e6d9f365bf63baa.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libshell32-f26d4446bb440430.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgdi32-cc8216356f37b045.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_device_gl-6f378e292a444005.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_core-aa43f82553171f18.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libdraw_state-419af1c9a7dd52da.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libbitflags-1b9f7576da940a38.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/liblog-342ffb7444a9471d.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libchrono-086951ef1dea2712.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libnum-98981edb917831dc.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libnum_iter-5766581f7597a504.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libnum_complex-c5081e842367373a.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libnum_rational-ee2647e9984d6d27.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libnum_bigint-d5ef62bdcef8e570.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libnum_integer-8f7844108d7e0eab.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/librand-c724acb3942597d1.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libnum_traits-14a2d70fdb554c2a.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_gl-565a5966718c12a7.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/librustc_serialize-3bc953984ed46e7f.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/liblibc-38919d24e617a235.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libspecs-5ca5e24705e76ffe.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libpulse-15b434d908f5854b.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libtime-71756e48b8b5b73b.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libtuple_utils-c0b4d4d00df3deee.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libatom-3108378d22af7662.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libthreadpool-0bb5a6ba1d0b4f62.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libkernel32-757937e2863677bb.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libwinapi-42bc588a308ea664.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libfnv-bbd2700436e7e891.rlib" "/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libmopa-2d8ed479fbf9b863.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-cb705824.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcollections-cb705824.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc-cb705824.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc_system-cb705824.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-cb705824.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librand-cb705824.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_unicode-cb705824.rlib" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-cb705824.rlib" "-l" "opengl32" "-l" "dwmapi" "-l" "user32" "-l" "shell32" "-l" "gdi32" "-l" "advapi32" "-l" "kernel32" "-l" "gcc_eh" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-l" "advapi32" "-l" "compiler-rt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "/home/marvin/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsend.o"
note: /usr/bin/ld: unrecognized option '--enable-long-section-names'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status

error: aborting due to previous error
error: Could not compile `fun1`.

Caused by:
  Process didn't exit successfully: `rustc src/main.rs --crate-name fun1 --crate-type bin -C opt-level=3 --out-dir /home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release --emit=dep-info,link --target x86_64-pc-windows-gnu -L dependency=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release -L dependency=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps --extern chrono=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libchrono-086951ef1dea2712.rlib --extern specs=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libspecs-5ca5e24705e76ffe.rlib --extern gfx_device_gl=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_device_gl-6f378e292a444005.rlib --extern glutin=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libglutin-fe8847f8e5c48a8d.rlib --extern cgmath=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libcgmath-76ab5db7eccfb351.rlib --extern gfx_window_glutin=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx_window_glutin-d2f847aed3bc91f3.rlib --extern gfx=/home/marvin/dev/rust/graphics_fun_2016-05-05/fun1/target/x86_64-pc-windows-gnu/release/deps/libgfx-dc2b98d25789486e.rlib -L native=/home/marvin/.cargo/registry/src/github.com-88ac128001ac3a9a/dwmapi-sys-0.1.0/x86_64` (exit code: 101)

Compiler version:

rustc 1.10.0-nightly (8da2bcac5 2016-04-28)
binary: rustc
commit-hash: 8da2bcac5db1e091b90cceb19d0496f0f7501c88
commit-date: 2016-04-28
host: x86_64-unknown-linux-gnu
release: 1.10.0-nightly
@Kimundi
Copy link
Member Author

Kimundi commented May 6, 2016

This is a dup of

#32859

@Kimundi Kimundi closed this as completed May 6, 2016
@Kimundi
Copy link
Member Author

Kimundi commented May 6, 2016

Actually, looking at #32859 in more detail this might be a different issue?

@Kimundi Kimundi reopened this May 6, 2016
@alexcrichton
Copy link
Member

Looks like the wrong linker is being used? The compiler is using "gcc"

@nagisa
Copy link
Member

nagisa commented May 16, 2016

~/.cargo/bin/rustup run nightly cargo rustc --release --target=x86_64-pc-windows-gnu -- -C linker=x86_64-w64-mingw32-gcc works, so we are invoking the wrong linker indeed.

@alexcrichton
Copy link
Member

Closing as I believe this was just the wrong linker being used.

@alexxroche
Copy link

alexxroche commented Apr 2, 2019

I tried cross compile today with rustc 1.33.0 (2aa4c46cf 2019-02-28) and cargo 1.33.0 (f099fe94b 2019-02-12) on debian 9. After rustup target add x86_64-pc-windows-gnu ; sudo apt-get install -y mingw-w64 the error that I got lead me straight here. Jorge Aparicio's rust-cross and Screwtape had the clue that solved it for me:

cat >>~/.cargo/config <<EOF
[target.x86_64-pc-windows-gnu]
linker = "/usr/bin/x86_64-w64-mingw32-gcc"
EOF

Then cargo build --release --target=x86_64-pc-windows-gnu worked. (cargo rustc --release --target=x86_64-pc-windows-gnu -- -C linker=x86_64-w64-mingw32-gcc also worked, but that doesn't seem like the more intuitive of the two options.)
[Sorry to necro this issue, but it doesn't feel closed. Maybe rustup target add ... should append to ~/.cargo/config ?]

@thmo
Copy link

thmo commented Jul 19, 2019

Should this work out of the box? It does not for me, I had to change ~/.cargo/config as described in the previous comment.

Therefore I think the issue should be reopened.

@elichai
Copy link
Contributor

elichai commented Sep 4, 2019

Agree. shouldn't rustc or whatever be able to find the correct linker itself?

@nagisa
Copy link
Member

nagisa commented Sep 4, 2019

rustc has the logic for finding a correct host toolchain, however the cross-toolchains can be present in varying forms, shapes and locations, making finding them automagically not very feasible.

@thmo
Copy link

thmo commented Sep 4, 2019

But wouldn't it already help to default the linker to at least a possible toolchain-specific linker (say x86_64-w64-mingw32-gcc in that case) instead of gcc, as the latter will be wrong for most if not all cross toolchains?

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

6 participants