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 not build Windows 32-bit executable with Cargo 1.32.0 on Windows 10 x64 #6754

Closed
62mkv opened this issue Mar 16, 2019 · 6 comments
Closed
Labels
C-bug Category: bug

Comments

@62mkv
Copy link

62mkv commented Mar 16, 2019

Problem
Trying to build simple Rust (v. 1.32.0) executable for Windows 32 (i686-pc-windows-gnu) and process fails with error: linking with gcc failed: exit code: 1

Steps

  1. src/main.rs:
fn main() {
   println!("Hello world");
}
  1. .cargo/config:
[build]
target = "i686-pc-windows-gnu"
  1. Cargo.toml:
[package]
name = "rust-est"
version = "0.1.0"
edition = "2018"

[dependencies]

  1. cargo build --verbose brings this:
>cargo clean

>cargo build --verbose
   Compiling rust-est v0.1.0 (C:\Develop\Rust\rust-est)
     Running `rustc --edition=2018 --crate-name rust_est src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=0aef5d6837db8b08 -C extra-filename=-0aef5d6837db8b08 --out-dir C:\Develop\Rust\rust-est\target\i686-pc-windows-gnu\debug\deps --target i686-pc-windows-gnu -C incremental=C:\Develop\Rust\rust-est\target\i686-pc-windows-gnu\debug\incremental -L dependency=C:\Develop\Rust\rust-est\target\i686-pc-windows-gnu\debug\deps -L dependency=C:\Develop\Rust\rust-est\target\debug\deps'
error: linking with 'gcc' failed: exit code: 1
  |
  = note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-Wl,--large-address-aware" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\crt2.o" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\rsbegin.o" "-L" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.2096vlwdaf95suba.rcgu.o" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.2lppayaq1wir2ypp.rcgu.o" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.2ssp982w1yrbisl6.rcgu.o" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.357wvgqemfx0xx00.rcgu.o" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.3ugcypndmhv2jp5w.rcgu.o" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.49qjssgcbcs5tunr.rcgu.o" "-o" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.exe" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps\\rust_est-0aef5d6837db8b08.2vr7a5ezmamolthw.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "C:\\Develop\\Rust\\rust-est\\target\\i686-pc-windows-gnu\\debug\\deps" "-L" "C:\\Develop\\Rust\\rust-est\\target\\debug\\deps" "-L" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib" "-Wl,--start-group" "-Wl,-Bstatic" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libstd-7e48495de01572b9.rlib" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libpanic_unwind-e84539ff24421dbe.rlib" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libunwind-a2c1ad3a7b70a902.rlib" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\liblibc-e50a71f5e96be797.rlib" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\liballoc-0f8e1992dbc35cee.rlib" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcore-d5c85fd1c00bcb9d.rlib" "-Wl,--end-group" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcompiler_builtins-e173d51a6e381521.rlib" "-Wl,-Bdynamic" "-ladvapi32" "-lws2_32" "-luserenv" "-lshell32" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "C:\\Users\\myuser\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\rsend.o"
  = note: ld: cannot find Files: No such file or directory
          ld: cannot find (x86)\ImageMagick-6.9.8-Q16-HDRI\lib: No such file or directory


error: aborting due to previous error

error: Could not compile 'rust-est'.

Caused by:
  process didn't exit successfully: rustc --edition=2018 --crate-name rust_est src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=0aef5d6837db8b08 -C extra-filename=-0aef5d6837db8b08 --out-dir C:\Develop\Rust\rust-est\target\i686-pc-windows-gnu\debug\deps --target i686-pc-windows-gnu -C incremental=C:\Develop\Rust\rust-est\target\i686-pc-windows-gnu\debug\incremental -L dependency=C:\Develop\Rust\rust-est\target\i686-pc-windows-gnu\debug\deps -L dependency=C:\Develop\Rust\rust-est\target\debug\deps' (exit code: 1)

Possible Solution(s)

If I comment out the [build]\target line in .cargo/config file, .exe file builds and runs fine. But I need to link it as a Win32-executable, because I need to call Win32-library from it. And if you call it from x64-executable, it throws a %1 is not a Win32 application error. :(

NB: by looking at

  = note: ld: cannot find Files: No such file or directory
          ld: cannot find (x86)\ImageMagick-6.9.8-Q16-HDRI\lib: No such file or directory

it feels as if a path to ImageMagick library folder is incorrectly parsed (or provided) without escaped spaces, but I have no slightest idea as to which tool might be the culprit here :(

Notes

Output of cargo version:
cargo 1.32.0 (8610973 2019-01-02)

Output of rustc version:
rustc 1.32.0 (9fda7c223 2019-01-16)

Windows 10 x64

@62mkv 62mkv added the C-bug Category: bug label Mar 16, 2019
@alexcrichton
Copy link
Member

It looks like there may be some environment variables in play here or perhaps a shell script along the way injecting arguments, but this unfortunately doesn't look like a cargo/rustc bug

@62mkv
Copy link
Author

62mkv commented Mar 18, 2019

ok @alexcrichton I understand it perfectly fine but how (as a cargo user) do I go about resolving it ? I can provide any information that's missing, so that we could decide which part of the toolset (if any) should this be raised for

@62mkv
Copy link
Author

62mkv commented Mar 18, 2019

first question - is this (i686-pc-windows-gnu) even legit toolchain to build Win32-application

@alexcrichton
Copy link
Member

Unfortunately this isn't the best venue to debug toolchain issues, but perhaps users.rust-lang.org can help?

@62mkv
Copy link
Author

62mkv commented Mar 18, 2019 via email

@62mkv
Copy link
Author

62mkv commented Mar 18, 2019

It seems I have it resolved:

  1. installed toolchain "stable-i686-pc-windows-msvc" (mentioned here as the toolchain for 32-bit Windows apps with MSVC)
  2. changed target in .cargo/config to target = "i686-pc-windows-msvc"
  3. added +stable-i686-pc-windows-msvc into cargo run command (I compile and run from IntelliJ)

So, thanks for suggestions, I think we may close this one!

@62mkv 62mkv closed this as completed Mar 18, 2019
Enselic added a commit to Enselic/bat that referenced this issue Jan 5, 2021
All the referenced issues have been closed:
rust-lang/rust#47048
rust-lang/rust#53454
rust-lang/cargo#6754

Since we can (and should) use 'stable' on these targets too, we don't
need the TOOLCHAIN logic any longer, so remove it.
Enselic added a commit to Enselic/bat that referenced this issue Jan 6, 2021
All the referenced issues [1] have been Closed, so use "stable" for
everything. Now `i686-w64-mingw32-gcc` fails with this instead

    error: linker `i686-w64-mingw32-gcc` not found

so keep it disabled. There is probably a simple solution for this that
is obvious to someone used to cross-compiling Rust programs on
Windows...

[1]
rust-lang/rust#47048
rust-lang/rust#53454
rust-lang/cargo#6754
sharkdp pushed a commit to sharkdp/bat that referenced this issue Jan 6, 2021
All the referenced issues [1] have been Closed, so use "stable" for
everything. Now `i686-w64-mingw32-gcc` fails with this instead

    error: linker `i686-w64-mingw32-gcc` not found

so keep it disabled. There is probably a simple solution for this that
is obvious to someone used to cross-compiling Rust programs on
Windows...

[1]
rust-lang/rust#47048
rust-lang/rust#53454
rust-lang/cargo#6754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants