Maintaining Exported Symbols as 'T' when Generating a C Dynamic Library with Rust

Hello,

I am working on generating a C dynamic library using Rust and have encountered an issue related to symbol exporting. In my build.rs, I link a C static library where all the symbols are of type 'T'. However, after building the project, the symbols from the static library in the final Rust-generated dynamic library change to 't', indicating they are no longer exported.

Here is how I am linking the libraries in build.rs:

Rust

深色版本

println!("cargo:rustc-link-search=native=./target/lib");
println!("cargo:rustc-link-arg=-Wl,--whole-archive");
println!("cargo:rustc-link-arg=-lclntcfg_static");
// println!("cargo:rustc-link-lib=static=clntcfg_static"); // Alternative approach, commented out
println!("cargo:rustc-link-arg=-Wl,--no-whole-archive");

The compilation command used is:

深色版本

RUSTFLAGS="-C link-dead-code" cargo build

Is there a way to retain the imported functions from the C static library as exported (i.e., keep their 'T' attribute instead of defaulting to 't') during the Rust build process without modifying the C library code? Any suggestions or pointers would be greatly appreciated.

Thank you!

This is from an unrelated bug I had in past. Maybe you get lucky and it also solves what you want.
To get some code working correctly I had to change the archiver used, to one supplied by the tool. Alternative is change the linker.

Could you elaborate a bit more on how you achieved this? Is the "archiver" you mentioned the one from the following link: archiver 0.3.2 - Docs.rs?

Also, I'm currently using the GCC toolchain. Does your solution still apply in this case, or would I need to make adjustments specific to GCC?

Too long ago to remember the details. Was patching the make file to get the change.
For creating static library ar but there are multiple from different projects. (Even version bumps have potential to cause breakage.)

Note I am only suggesting to look to see if relevant; I don't know the details of what your trying.

I don't think there is currently a good way. There is an open issue discussing this feature: Re-exporting C symbols for cdylib · Issue #2771 · rust-lang/rfcs · GitHub

If you output a static library I believe the symbol will retain the 'T' type.

In that linked issue there's also a macro you might be able to use to rexport symbols by redeclaring functions.

thank you!