I'm trying to export a symbol from a Rust executable:
#[allow(non_upper_case_globals)]
#[no_mangle]
pub static exported_symbol: [u8; 1] = *b"\0";
fn main() {
println!("Hello, world!");
}
exported_symbol
doesn't appear to be exported by the resulting binary:
$ cargo build
$ nm ./target/debug/test_export| grep exported_symbol
On the other hand, if I build a library with the same source, the symbol does get exported:
$ rustc --crate-type cdylib src/main.rs
$ nm libmain.so| grep exported_symbol
0000000000016c10 R exported_symbol
I'm using Rust 1.18.0 on Linux x86-64.
You can pass linker options to rustc, like:
$ rustc src/main.rs --crate-type bin -C link-args=-Wl,-export-dynamic
$ nm main|grep export
00000000000d79c4 R exported_symbol
You'll probably want to put this in your rustflags in your .cargo/config something like:
[target.x86_64-unknown-linux-gnu]
rustflags = [ "-C", "link-args=-Wl,-export-dynamic" ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With