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

nightly: Cross compiling to x86_64-pc-windows-gnu fails #14392

Closed
SecTheBit opened this issue Aug 13, 2024 · 4 comments
Closed

nightly: Cross compiling to x86_64-pc-windows-gnu fails #14392

SecTheBit opened this issue Aug 13, 2024 · 4 comments
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@SecTheBit
Copy link

Problem

I tried to compile a simple Hello World program (generated using cargo new abcd) on ubuntu machine for x86_64-pc-windows-gnu using nightly toolchain, but its giving error. (refer to below screenshots)

Screenshot (173)

I also tried to include the standard library for resolving the above error using following command
cargo +nightly build --target=x86_64-pc-windows-gnu -Z build-std=std,panic_abort

Output:

   Compiling compiler_builtins v0.1.118
   Compiling core v0.0.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.155
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling unwind v0.0.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind)
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.24
   Compiling rustc-std-workspace-alloc v1.99.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_abort v0.0.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
   Compiling gimli v0.29.0
   Compiling object v0.36.2
   Compiling std_detect v0.1.5 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling miniz_oxide v0.7.4
   Compiling hashbrown v0.14.5
   Compiling panic_unwind v0.0.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_unwind)
   Compiling addr2line v0.22.0
   Compiling proc_macro v0.0.0 (/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro)
   Compiling abcd v0.1.0 (/home/scorpion/tools/temp/abcd)
error: linking with `/usr/bin/x86_64-w64-mingw32-gcc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/scorpion/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/scorpion/.cargo/bin:/home/scorpion/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin" VSLANG="1033" "/usr/bin/x86_64-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "rsbegin.o" "/tmp/rustclTWO2h/symbols.o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.0acnxw7gtse9lb7sxt4shl1qh.rcgu.o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.0k1h1o3e9ceqvljvnqsiok5r9.rcgu.o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.3gu6v2566101yogh5wnyhchjj.rcgu.o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.4ey6z48p3trb6j5hwqyzdm9bk.rcgu.o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.6o652ros8nliqurvbkzzkt0w8.rcgu.o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.98v116utrp9fw03irbibealm1.rcgu.o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.3bhikv3dvoj2axeh3bkpploin.rcgu.o" "-Wl,-Bstatic" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libstd-d134e941b884cad9.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libpanic_unwind-d1f1e49a237738b7.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libobject-539cb2946bb9bc1b.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libmemchr-bbe242f3b0278e84.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libaddr2line-cce60b0071f7dea2.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libgimli-bb687e8086fbe64e.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/librustc_demangle-14fbf210022bd30b.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libstd_detect-9da27193a84cc3bb.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libhashbrown-67f5d1f728ba7675.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/librustc_std_workspace_alloc-02e34a89cfd6902f.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libminiz_oxide-ce14eb50160b6da1.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libadler-4b453f0116368c9e.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libunwind-48598c9f51e30c1f.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libcfg_if-1287809dec47833b.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/liblibc-fca58c54e6b000e1.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/liballoc-175264874b4b92a0.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/librustc_std_workspace_core-f3310a9dcd786861.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libcore-aa04dcfd7114712a.rlib" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/libcompiler_builtins-cc9e846f588dd289.rlib" "-Wl,-Bdynamic" "-lkernel32" "-ladvapi32" "-lntdll" "-luserenv" "-lws2_32" "-lkernel32" "-lkernel32" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-o" "/home/scorpion/tools/temp/abcd/target/x86_64-pc-windows-gnu/debug/deps/abcd-6bc50d6f1bb7d8c3.exe" "-Wl,--gc-sections" "-no-pie" "-nodefaultlibs" "rsend.o"
  = note: /usr/bin/x86_64-w64-mingw32-ld: cannot find rsbegin.o: No such file or directory
          /usr/bin/x86_64-w64-mingw32-ld: cannot find rsend.o: No such file or directory
          collect2: error: ld returned 1 exit status
          

error: could not compile `abcd` (bin "abcd") due to 1 previous error

Steps

  1. Create a new project on ubuntu machine using cargo
  2. Try to compile using nightly for x86_64-pc-windows-gnu target
  3. It will generate the above errors

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.80.1 (376290515 2024-07-16)
release: 1.80.1
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 24.4.0 (noble) [64-bit]

 rustup --version ```
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.80.1 (3f5fd8dd4 2024-08-06)`

``` rustc --version --verbose```
rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7

``` lsb_release -a``` (info about ubuntu machine)
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04 LTS
Release:	24.04
Codename:	noble
@SecTheBit SecTheBit added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Aug 13, 2024
@workingjubilee
Copy link
Member

workingjubilee commented Aug 14, 2024

@SecTheBit You should not need to specify more than -Zbuild-std. If you provide any arguments to -Zbuild-std it is best to exhaustively list every single package that you require.

This is not an issue with cargo, except insofar as -Zbuild-std may need better UX for that.

Please try again with rustup target add.

@ChrisDenton
Copy link
Member

You'll also need to set -Zbuild-std-features to not include panic-unwind if you're not unwinding https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features

@ehuss
Copy link
Contributor

ehuss commented Aug 14, 2024

From your original screenshot, when you do:

rustup target add x86_64-pc-windows-gnu

This added the target for the default toolchain, which in your case is stable-x86_64-unknown-linux-gnu. However, you then run cargo +nightly build --target x86_64-pc-windows-gnu. The +nightly selected a different toolchain. If you wanted to build for nightly, you would need something like rustup target add --toolchain nightly x86_64-pc-windows-gnu.

As for supporting things like rsbegin with -Z build-std, we don't have a way of supporting those, yet. That is tracked in rust-lang/wg-cargo-std-aware#46.

Closing as this doesn't look like it is a cargo issue, but instead a misunderstanding of how rustup works. If you have further questions about how to set up your environment, I would suggest using one of the user forums such as https://users.rust-lang.org/.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
@SecTheBit
Copy link
Author

rustup target add x86_64-pc-windows-gnu --toolchain nightly x86_64-pc-windows-gnu

This command helped me to resolve the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

4 participants