I run x86_64 Fedora Linux 31 host and want to compile some simplest rust code:
fn main() {
println!("Hello, world!");
}
It compiles from the host to this host natively fine but when I try to cross compile it to either i686 or x86_64 windows it fails to compile.
I read stackoverflow (for example here) and googled the Internet trying to find out similar problem and how to solve it but with no profit.
I have installed all the targets necessary:
[pfemidi@pfemidi hello_cargo]$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/pfemidi/.rustup
installed targets for active toolchain
--------------------------------------
i686-pc-windows-gnu
i686-unknown-linux-gnu
i686-unknown-linux-musl
x86_64-pc-windows-gnu
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.39.0 (4560ea788 2019-11-04)
[pfemidi@pfemidi hello_cargo]$
I have installed as mingw32 as mingw64, this little test C++ code has been compiled as by mingw32 as mingw64 just fine and with no errors:
#include <iomanip>
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
I have added windows specific mingw linker and ar to my .cargo/config:
[target.i686-pc-windows-gnu]
linker = "i686-w64-mingw32-gcc"
ar = "i686-w64-mingw32-ar"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-ar"
But when I run either
cargo build --release --target i686-pc-windows-gnu --verbose
or
cargo build --release --target x86_64-pc-windows-gnu --verbose
both complain "cannot find -lpthread":
[pfemidi@pfemidi hello_cargo]$ cargo build --release --target i686-pc-windows-gnu --verbose
Compiling hello_cargo v0.1.0 (/home/pfemidi/mywork/rust/hello_cargo)
Running `rustc --edition=2018 --crate-name hello_cargo src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C metadata=3801b83c24480675 -C extra-filename=-3801b83c24480675 --out-dir /home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-ar -C linker=i686-w64-mingw32-gcc -L dependency=/home/r/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps -L dependency=/home/r/mywork/rust/hello_cargo/target/release/deps`
error: linking with `i686-w64-mingw32-gcc` failed: exit code: 1
|
= note: "i686-w64-mingw32-gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-Wl,--large-address-aware" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.0.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.1.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.10.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.11.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.12.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.2.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.3.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.4.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.5.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.6.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.7.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.8.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.9.rcgu.o" "-o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.exe" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.3miif37looiovbes.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps" "-L" "/home/pfemidi/mywork/rust/hello_cargo/target/release/deps" "-L" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libstd-78187cf09a9bef6f.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_abort-699459bd9d6c1638.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libhashbrown-397a481a32803af5.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_alloc-27eb482dce24475f.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libbacktrace-046a61f77fc212c5.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libbacktrace_sys-8c6fe5218eaa7203.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/librustc_demangle-4d4d47417516248c.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libunwind-ef8ccbbd42d1b53f.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcfg_if-bbe68dc13352b6cc.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/liblibc-b6447d8e4c58855b.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/liballoc-3890c13f15229667.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_core-ceab434c37c7417c.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcore-3b2fced4ccf446c5.rlib" "-Wl,--end-group" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcompiler_builtins-7e358676639674ac.rlib" "-Wl,-Bdynamic" "-ladvapi32" "-lws2_32" "-luserenv" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
= note: /usr/lib/gcc/i686-w64-mingw32/9.2.1/../../../../i686-w64-mingw32/bin/ld: cannot find -lpthread
collect2: error: ld returned 1 exit status
error: aborting due to previous error
error: could not compile `hello_cargo`.
Caused by:
process didn't exit successfully: `rustc --edition=2018 --crate-name hello_cargo src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C metadata=3801b83c24480675 -C extra-filename=-3801b83c24480675 --out-dir /home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-ar -C linker=i686-w64-mingw32-gcc -L dependency=/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps -L dependency=/home/pfemidi/mywork/rust/hello_cargo/target/release/deps` (exit code: 1)
[pfemidi@pfemidi hello_cargo]$
Why? What else should I do to satisfy everything?