Re-exporting extern "C"
and `#[no_mangle] symbols in cdylib doesn’t work with gcc on Linux
#63125
Labels
A-FFI
Area: Foreign function interface (FFI)
A-linkage
Area: linking into static, shared libraries and binaries
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Building a
cdylib
crate that has a dependency on a crate withextern "C"
and#[no_mangle]
symbols fails to export the symbols on Linux, even when the symbols are re-exported as public. Symbols are correctly exported on Mac and Windows.The problem was somewhat discussed on #36342 but as far as I can tell, only
gcc
and Linux are behaving abnormally today.In order to reproduce the issue, I used the following simple setup with two crates.
mycrate/Cargo.toml
mycrate/src/lib.rs
mylib/Cargo.toml
mylib/src/lib.rs
I then ran
cargo build
inmylib
and inspected the resulting library undermylib/target/debug
.On Mac
On Windows
On Linux
I expected
do_you_see_me
to be exported by the dynamic library on Linux too.This makes it pretty hard to ship a
cdylib
built on top of crates that expose a C ABI. I realize that it’s technically possible to "wrap" the symbols frommycrate
in new#[no_mangle]
andextern "C"
functions inmylib
but for a project with a substantial number of exported symbols it’s simply not practical.Meta
Versions of
rustc
and various compilers I am using.On Mac
On Linux
On Windows
The text was updated successfully, but these errors were encountered: