Reputation: 537
I am using Rust in a Meson based build-system where I build a static library that I need to link to a Rust crate built with Cargo. Right-now I use this environment variable in my Cargo invocation:
'CARGO_ENCODED_RUSTFLAGS': '-lnative='+my_static_lib.full_path(),
However Cargo complain that it cannot find the static library.
When I attempt a dirty hack by using -L
to add a search directory and -l
with only the library name Cargo don't find the library because it adds platform specific prefix/suffix.
I saw that Rust #[link] attribute have a +verbatim
modifier that may have some potential but it expect the name of the library and does not accept env!()
macros right-now.
I want a clean way to link the Rust program to the static library. How ?
Upvotes: 0
Views: 84
Reputation: 537
It's dirty and will break if there are spaces in the filename but Rust allows passing custom linker arguments.
Adding the static library to linker arguments allow it to be included during linkage on my machine:
custom_target('cargo-with-my_static_lib',
# ...
env: {
'CARGO_ENCODED_RUSTFLAGS': '\x1f'.join(['-C','link-args='+my_static_lib.full_path()]),
},
depends: my_static_lib,
)
Upvotes: 0