Libstd undefined symbols when building dylib


I’m making a library which I want to call from C/++. I have a main rust crate (rlib), then a simple wrapper crate that wraps the main crate’s functionality using extern “C” functions. If I build the wrapper crate as a staticlib I can link against it from C++ just fine, and everything works as expected. If I change my crate type to dylib though I get a whole bunch of undefined symbols when trying to link to it from C++:

/usr/bin/ld: warning:, needed by 
/home/anders/packages/rama/0.1.0/lib/, not found (try using -rpath or -rpath-link)
/home/anders/packages/rama/0.1.0/lib/ undefined reference to `std::io::stdio::Stdout::lock::h25c724b0429bb7d6'
... etc etc x100...

I don’t see the anywhere in my target directory, although I do see some .so’s for dependent crates (e.g. serde).


You should set your crate type to cdylib.


That did indeed work, thanks! I’d thought the cdylib was for something else.


To make it more clear, here’s an extract from reference.

  • bin: ordinary executable.
  • lib: a library to be linked statically into Rust programs.
  • dylib: a library to be linked dynamically into Rust programs.
  • staticlib: a library to be linked statically into non-Rust programs.
  • cdylib: a library to be linked dynamically into non-Rust programs.

(plus rlib as mainly internal format and proc_macro, used, well, for procedural macros)


Thanks, that’s very clear. I realise now that the page I’d found as an example through google: is woefully out of date…