Rust cannot link with `x86_64-w64-mingw32-gcc`

I am trying to make a get request to a url with rust and everytime I run this project I get this error, my other rust project work fine. here's my cargo.toml file.

[package]
name = "api_req"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"]}

this is the output I get when I try to build/run the code.

error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: 

Upvotes: 7

Views: 7209

Answers (3)

Pablo Johnson
Pablo Johnson

Reputation: 1072

It is not the exact answer to your problem but another way to cross-compile and a very simple one is using cargo-cross. Steps:

  • cargo install cargo-cross
  • install docker or any other container engine.
  • Example commands:
    • cross build --target x86_64-unknown-linux-gnu
    • cross run--target x86_64-unknown-linux-gnu

Instructions and usage in https://github.com/cross-rs/cross/blob/main/docs/getting-started.md

Upvotes: -1

Mikolasan
Mikolasan

Reputation: 785

  1. Find where MinGW is installed. I have mine in C:\msys64 as part of MSYS2 installation.

  2. In the root of your Rust project create a .cargo folder.

  3. Inside the .cargo folder, create a config.toml file with the following content (adjust for MinGW installation path in your system):

[target.x86_64-pc-windows-gnu]
linker = "C:\\msys64\\mingw64\\bin\\gcc.exe"
ar = "C:\\msys64\\mingw64\\bin\\ar.exe"
  1. Now try cargo build or cargo run

Upvotes: 0

FrankHB
FrankHB

Reputation: 2495

This is a known bug which should have been by the resolution for another issue.

Just update by rustup update or by any package manager you installed the toolchain.

Upvotes: 2

Related Questions