Cross compiling issue with static linking

Hello all,

I'm trying to cross-compile my program from Linux (x86_64 Archlinux) to Windows. I followed the wiki and managed to successfully cross-compile with :

cargo build --release --target "x86_64-pc-windows-gnu"

Great. Cross-compiling is easy ! :slight_smile:

Well... unfortunately Windows can't execute the binary because it can't find the libstdc++-6.dll.

I tried a static build of the stdc++ by adding this in my build.rs :

println!("cargo:rustc-link-lib=static=stdc++");

But it won't compile anymore... I really don't understand what I can do about it. Any clue?


= note: /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libstdc++.a(compatibility-condvar.o):/build/mingw-w64-gcc/src/build-x86_64-w64-mingw32/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:733: undefined reference to `__imp_pthread_mutex_init'
          /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libstdc++.a(compatibility-condvar.o):/build/mingw-w64-gcc/src/build-x86_64-w64-mingw32/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:740: undefined reference to `__imp_pthread_mutex_destroy'
          collect2: error: ld returned 1 exit status

  = 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)

EDIT: For now my workaround is to copy the libstdc++-6.dll next to my .exe

EDIT2: I tried the nightly static_nobundle feature :

#![feature(static_nobundle)]

fn main() {
    println!("cargo:rustc-link-lib=static-nobundle=stdc++");
}   

The compilation succeed (!) But no luck this doesn't solve the initial problem. Windows still asks for the libstdc++-6.dll :frowning:

Similar issue : https://users.rust-lang.org/t/where-do-i-get-libstdc-6-dll

EDIT 3: This is maybe related : https[:]//github[.]com/rust-lang/rust/pull/88227 (can't put more link as a new user)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.