When I try to do this, the compiler displays a warning
warning: attribute should be applied to an `extern` block with non-Rust ABI
--> src\main.rs:3:1
|
3 | #[link(name="b")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: `#[warn(unused_attributes)]` on by default
and ignores this attribute thereby causing an error, I have to use the syntax "-l" and it works. What is the meaning of this restriction?
Guess that isn't allowed then. Note that C libraries can't use the Rust abi and if you are using a rust library, you almost certainly shouldn't use #[link] either. Only if you can ensure that the exact same rustc version is used is it maybe allowed. And even then anything type that containes allocated memory is not allowed either.
If you use -l with a rust dynamic library, the assumption is that the exported interface uses the C abi, not the Rust abi. Rustc has no way to check if this is true or not.