I'm developing a libfoo-sys crate with low level bindings for an third-party C-library and a libfoo-crate on top of that. In the build-script of libfoo-sys I check out the original source from git.
I want to prevent that users have to globally install stuff into their system.
I build the library in the directory of the git submodule, and install the library locally into ./lib-out. Inside ./lib-out After building, I get the shared object file that has the following dependencies:
linux-vdso.so.1 (0x00007ffc9eff6000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f07870b0000)
libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f078702b000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0786e49000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0786c57000)
/lib64/ld-linux-x86-64.so.2 (0x00007f078734f000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0786c3c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0786aeb000)
My build-script tells Rustc to use static linkage:
println!("cargo:rustc-link-lib=static=foo");
However, as soon as I use static linkage, Rustc can't find C++ symbols. etc. I guess I have to also link all the dependencies manually. However, I don't know a generic way how println!("cargo:rustc-link-lib=static=stdc++"); will work in the end. I can't find a libstdc++.so in my file system but only a libstdc++.so.6 which is not compatible with cargo:rustc-link-lib (or at least I don't know how). Any advices?
PS: I'm aware of that you should refrain from linking glibc statically and I guess the same applies for the c++ std as well. However, primarily I'd like to figure out if it makes sense and brings a benefit to statically link the library and use the self compiled version instead of a globally installed version