Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

musl-gcc required when building with target=x86_64-unknown-linux-musl #34

Closed
vishvananda opened this issue Feb 22, 2017 · 9 comments
Closed

Comments

@vishvananda
Copy link

When building backtrace-sys for x86_64-unknown-linux-musl I got the following errors:

error: failed to run custom build command for `backtrace-sys v0.1.10`
...
configure: error: C compiler cannot create executables
See `config.log' for more details.

Opening up the config.log i saw:

musl-gcc: command not found

On ubuntu I can fix this with apt-get install musl-tools.

I suspect there is no workaround for this, but it probably should be noted in the readme that a compiler is required to build this, and specifically musl-gcc if building for the the musl target.

@rogeruiz
Copy link

rogeruiz commented Jun 23, 2017

I'm running into this issue as well when trying to cross-compile my Rust project using the target x86_64-linux-musl-gcc. I'm not sure how I can update the C compiler to use the one that I installed to do the cross-compilation.

The following cargo configuration allowed me to cross-compile a much simpler project that didn't include backtrace-rs.

$ cat ~/.cargo/config
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
$ cargo build --release --target x86_64-unknown-linux-musl
   Compiling bitflags v0.8.2
   Compiling cfg-if v0.1.1
   Compiling ansi_term v0.9.0
   Compiling num-traits v0.1.39
   Compiling utf8-ranges v1.0.0
   Compiling yaml-rust v0.3.5
   Compiling byteorder v1.0.0
   Compiling vec_map v0.8.0
   Compiling unicode-segmentation v1.2.0
   Compiling unicode-width v0.1.4
   Compiling rustc-demangle v0.1.4
   Compiling libc v0.2.23
   Compiling void v1.0.2
   Compiling unreachable v0.1.1
   Compiling strsim v0.6.0
   Compiling libsqlite3-sys v0.8.1
   Compiling backtrace-sys v0.1.11
   Compiling regex-syntax v0.4.1
   Compiling term_size v0.3.0
   Compiling memchr v1.0.1
   Compiling time v0.1.37
   Compiling num-integer v0.1.34
error: failed to run custom build command for `backtrace-sys v0.1.11`
process didn't exit successfully: `/Users/rsr/Developer/oss/tick/target/release/build/backtrace-sys-6725bb7e0db87b3e/build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-unknown-linux-musl")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-unknown-linux-musl = None
CC_x86_64_unknown_linux_musl = None
TARGET_CC = None
CC = None
HOST = Some("x86_64-apple-darwin")
CROSS_COMPILE = None
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
PROFILE = Some("release")
running: "sh" "/Users/rsr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.11/src/libbacktrace/configure" "--with-pic" "--disable-multilib" "--disable-shared" "--disable-host-shared" "--host=x86_64-unknown-linux-musl" "--build=x86_64-apple-darwin"
checking build system type... x86_64-apple-darwin
checking host system type... x86_64-unknown-linux-musl
checking target system type... x86_64-unknown-linux-musl
checking for x86_64-unknown-linux-musl-gcc... musl-gcc
checking for C compiler default output file name...

--- stderr
configure: error: in `/Users/rsr/Developer/oss/tick/target/x86_64-unknown-linux-musl/release/build/backtrace-sys-204dc57c91e9a514/out':
configure: error: C compiler cannot create executables
See `config.log' for more details.
thread 'main' panicked at 'failed with: exit code: 77', /Users/rsr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.11/build.rs:136
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Build failed, waiting for other jobs to finish...
error: build failed

@alexcrichton
Copy link
Member

@rogeruiz the .cargo/config configuration tells Cargo what linker to use, but unfortunately that's different than the configuration used to tell build scripts what compiler to use. For that you'll want to use the environment variable CC_x86_64-unknown-linux-musl=...

@rogeruiz
Copy link

Thanks @alexcrichton. Looks like I'm running into other issues related to -lsqlite3 and I'll need to point the the compiler to the libraries for sqlite3. 😬

I think I may just follow the process of having my rust project build in an actual Linux environment. thanks again!

@olegantonyan
Copy link

olegantonyan commented Mar 6, 2018

@alexcrichton how to pass env variable with dashes in it? CC_x86_64-unknown-linux-musl=.. is not a valid env variable name. upd. https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables replace dashes with underscores

@alexcrichton
Copy link
Member

Indeed yeah, dashes to underscores should work!

@alexcrichton
Copy link
Member

I'm going to close this as this is largely working as expected

@chaseSpace
Copy link

chaseSpace commented Oct 21, 2022

For cross compile, you can add env args TARGET_CC:
TARGET_CC=x86_64-linux-musl-gcc cargo build --release --target x86_64-unknown-linux-musl

@gustawdaniel
Copy link

On Fedora fixed by

sudo dnf install musl-gcc

or by

sudo dnf install zig
cargo install cargo-zigbuild
cargo zigbuild --target x86_64-unknown-linux-musl

https://github.com/rust-cross/cargo-zigbuild

@GregPK
Copy link

GregPK commented May 8, 2024

On archlinux:

sudo pacman -S musl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants