Link the `rand` crate to C has missing symbols?


I’m experimenting with calling Rust from C, however I’m hitting issues with linking when using the rand crate. I’m using crate-type=["staticlib"] to link to the C objects, but during the link phase I get missing symbols, possibly related to rust_core.

I’ve created a minimal example of the problem here:
On OS X it results in the follwing errors (amongst others):

Undefined symbols for architecture x86_64:
"_SecRandomCopyBytes", referenced from:
  _$LT$rand..rngs..os..OsRng$u20$as$u20$rand_core..RngCore$GT$::fill_bytes::hcd1750a2ddb4a65c in libutil_rust.a(

On Linux it looks like:

In function `std::sync::once::Once::call_once::{{closure}}':$u7b$$u7b$closure$u7d$$u7d$17hb410b94add473a2cE+0x4c): undefined reference to `pthread_mutexattr_init'

Does anyone have any suggestions for making this work?


You’ll need to link the C binary with Security.framework on OSX and libpthread on Linux.


Perfect, thanks!