Cross-compile from Windows host to Linux-musl target not working for crate x11

I want to cross-compile as the title states. A not telling error is blocking me for compiling my project.

Followed a tutorial:

Which can be summarized as:

rustup target add x86_64-unknown-linux-musl

Then in "./cargo/config":

[target.x86_64-unknown-linux-musl]
linker = "rust-lld"

But build fails with:

> cargo build --target x86_64-unknown-linux-musl
   [... omitted for brevity ...]
   Compiling x11 v2.18.2
error: failed to run custom build command for `x11 v2.18.2`

Caused by:
  process didn't exit successfully: `C:\user\project\target\release\build\x11-c78bae3b1400f31f\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=X11_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CrossCompilation', C:\user\.cargo\registry\src\github.com-1ecc6299db9ec823\x11-2.18.2\build.rs:36:67
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

Found a similar question in StackOverflow: rust - How do I build a project that uses the device_query crate on WSL? - Stack Overflow but the error in that question is much more telling than my "value: CrossCompilation"

How can I fix the error?

Looks like there's a solution: https://github.com/erlepereira/x11-rs/issues/96#issuecomment-522299079

1 Like

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.