Linking with `gcc` failed: exit code: 1

I'm trying to cross compile the triangle example from vulkano. I followed the 'cross-compile to windows-gnu from windows-msvc' instructions provided by them, just to make sure that I could compile the example code. but unfortunately I'm getting the following error:

Compiling vulkano-shaders v0.13.0

error: linking with gcc failed: exit code: 1

= note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "C:\Program Files\Rust stable GNU 1.36\lib\rustlib\x86_64-pc-windows-gnu\lib\dllcrt2.o" "C:\Program Files\Rust stable GNU 1.36\lib\rustlib\x86_64-pc-windows-gnu\lib\rsbegin.o" "-L" "C:\Program Files\Rust stable GNU 1.36\lib\rustlib\x86_64-pc-windows-gnu\lib"...

error: Could not compile vulkano-shaders.

Here's the full error log: C:\Users\Luis\Desktop\Programming\Rust_Projects\vulkano-examples>cargo run --tar - Pastebin.com

I followed the workaround that daniel-shimon provides to solve the issue, but now the error is almost the same: "error: linking with gcc failed: exit code: 1" and it complains with the following:

= note: ld: cannot find -lworkaround_47048

error: aborting due to previous error

error: Could not compile libc.
warning: build failed, waiting for other jobs to finish...
error: Could not compile proc-macro2.
warning: build failed, waiting for other jobs to finish...
error: Could not compile arrayvec.
warning: build failed, waiting for other jobs to finish...
error: build failed

What am I doing wrong? Maybe there's a conflict in my path? I noticed that I have Mingw, Cygwin64 and msys64 installed; does this have to do with my problem?

= note: ld: cannot find -lworkaround_47048

Are you sure you did all steps of https://github.com/rust-lang/rust/issues/47048#issuecomment-530376978 without getting errors?

Please redo the steps from start and paste the output of the commands here if any.

Hi! Thanks for your comment. Yes, seems like I missed one step, I forgot to run the command that in that thread mentions: rustup component remove rust-mingw . I started from zero just to make sure, but yet the error is almost the same. I did make sure that msys64\mingw64\bin is in my path; I runned pacman -S mingw-w64-x86_64-toolchain in the msys2_shell, everything is already installed; I already have CMake too; I even copied the crt2.o and dllcrt2.o files from C:\msys64\mingw64\x86_64-w64-mingw32\lib to ~\.rustup\toolchains\stable-x86_64-pc-windows-gnu\lib\rustlib\x86_64-pc-windows-gnu\li directory, like in the said issue mentions.

But I'm getting: undefined reference to '__imp___acrt_iob_func'. That was the first error that leads me to the workaround I'm following.

Here's what is inside my ./cargo/config (I'm not sure if it was necessary to modify that file, though):
[target.x86_64-pc-windows-gnu]
rustflags=["-Clink-args=-lworkaround_47048"]

My current toolchain is stable-x86_64-pc-windows-msvc. I'm running the triangle example with: cargo build --target x86_64-pc-windows-gnu --bin triangle

I really don't know what to do, I'm running out of ideas :slightly_frowning_face:

I have no idea but my config file has those lines below under [target.x86_64-pc-windows-gnu] in addition to rustflags=["-Clink-args=-lworkaround_47048"] so maybe try:

linker = <mingw64 gcc path>
ar = <mingw64 ar path>

I tried:
[target.x86_64-pc-windows-gnu]
rustflags=["-Clink-args=-lworkaround_47048"]
linker="C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-gcc.exe"
ar="C:\\msys64\\mingw64\bin\\ar.exe"

I'm getting this:
error: linking with C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe failed: exit code: 1

collect2.exe: error: ld returned 1 exit status

error: aborting due to previous error

error: Could not compile vulkano-shaders

I'm glad the errors are changing though :stuck_out_tongue_winking_eye:

Please post whole output.

Here's the full error!

But this is the same undefined reference to __imp___acrt_iob_func error. By viewing the command line arguments, I see -lworkaround_47048 is not getting passed to the linker. Make sure your setting is read by e.g. try changing it to -ldummy_nonexist and see getting an error.

After following your instructions, the config file looks like this:
[target.x86_64-pc-windows-gnu]
rustflags=["-Clink-args=-ldummy_nonexist"]
linker="C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-gcc.exe"
ar="C:\\msys64\\mingw64\bin\\ar.exe"

However, the error is the same: full error here. What does this mean? I'm missing a step?

Probably your config file is in wrong place.
It has to be in C:\Users\<user name>\.cargo\config without extension.

Try this command in PowerShell:

notepad $env:USERPROFILE\.cargo\config

Apparently is in the right place :slightly_frowning_face:, running that command just returns the same file I was editing.

Do you have RUSTFLAGS environment variable set (echo $env:RUSTFLAGS) or is there any other .cargo/config file to your current directory or any of its ancestor directories? The configuration can be overridden.

I think I don't have that variable set. Should I run echo $env:RUSTFLAGS in Powershell to make sure? And no, that's the only .cargo/config file I have in my current directory. I would like to mention that I've been running my binary with the following command: cargo build --target=x86_64-pc-windows-gnu --bin triangle, is that correct?

Try cargo clean.

This is the output after running cargo clean and then building my project again. It's complaining about CMake? I did make sure that I have C:\Program Files\CMake\bin in my path.

Thanks a lot for taking the time in trying to help me, by the way. This problem has been chasing me for days.

Well, at least you are now getting a different error. I'm done for now. Good luck!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.