'Link error when using actix-web and tokio
I have a simple actix-web application (the example from the documentation) with actix-web and tokio as dependencies in Cargo.toml. Running cargo run give me this error:
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
|
= note: "x86_64-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" ...
...
...
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
From my research, I tried reinstalling cargo and updating the crates, but that didn't work. Running a hello world program works. I suspect the error is from the main function, as commenting that out and running the program does not error out. My code for reference:
#[allow(unused_imports)]
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
#[allow(dead_code)]
async fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}", name)
}
#[tokio::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
})
.bind("127.0.0.1:8000")?
.run()
.await
}
My Cargo.toml file:
[package]
name = "proj_actix"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "4"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
I also set my default toolchain as such: rustup default stable-x86_64-pc-windows-gnu (I had an error just after installing Rust, nothing was running but that fixed it). I'm on Windows 10.
What could be the problem here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
