rust

How to I tell Rust where to look for a static library?


Is there any way to tell Rust where to look for my static library? Example code

#[link(name = "/this/is/the/path/libfoo.a", kind = "static")]

If not, what config change can I make or what folder do I place my library in so that I can use it?


Solution

  • rustc invokes the system linker which looks for all libraries specified in #[link(...)] in library directories. There are usually several default library directories (like /lib and /usr/lib on Linux), and more can be specified via linker flags (rustc accepts -L options which it then passes through to the linker).

    If you invoke rustc directly, you can use the -L option to add additional library directories which will be then passed through to the linker. If you use Cargo, however, you've got a few more options:

    The easiest way for you, I think, is to add a custom build script which will copy or create a symlink to your library in the corresponding /target/<profile>/deps directory.