6

I successfully created a musl configured rustc by following this link

My attempt to build a project (which builds fine using non-musl configured rust) failed when I used cargo rustc -- --target=x86_64-unknown-linux-musl

 'error: could not find crate `libc` with expected target triple x86_64-unknown-linux-musl'

Then, I tried to create rust-libc library using the code from crate. To be more accurate, I used the command provided by cargo to build rust-libc, I've only added --target=x86_64-unknown-linux-musl to the command. This time it failed reporting:

'error: could not find native static library `c`, perhaps an -L flag is missing?`'

I have two questions:

  • Is it mandatory to build musl configured cargo to be able to use cargo build --target=x86_64-unknown-linux-musl?

  • How can I address this:

    'error: could not find native static library `c`, perhaps an -L flag is missing?'
    
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
M Moadeli
  • 99
  • 6
  • You wrote that you typed "cargo rustc -- --target=x86_64-unknown-linux-musl" . Is there a "rustc" option of cargo or should that be "build"? "cargo build" works without musl. – Scooter Aug 06 '15 at 11:15
  • cargo build works, but the built library does not have the dependencies statically linked. – M Moadeli Aug 06 '15 at 11:25
  • Your first question should probably be reworded. "in order to use cargo build" must need something else, because you are saying you can use "cargo build". Can you build a fully statically-linked executable by calling rustc directly the way they did at the bottom of the instruction page you linked to? – Scooter Aug 06 '15 at 11:31
  • yes, I created the example.rs in the link and verified it having no dependencies. – M Moadeli Aug 06 '15 at 11:37

1 Answers1

3

This worked for me to build libc:

rustc --target=x86_64-unknown-linux-musl /address-of-libc/lib.rs --crate-name libc --crate-type lib -L /address-of-musldist/musldist/lib/ --out-dir=/your-chosen-address/target --cfg feature=\"default\" --cfg feature=\"cargo-build\" --emit=dep-info,link

tshepang
  • 12,111
  • 21
  • 91
  • 136
M Moadeli
  • 99
  • 6