openblas-src
openblas-src copied to clipboard
Link libgfortran statically when `features=static`
Hello Team,
With openblas static feature, it can be linked statically but the gfortran itself was linked dynamically (gcc -lgfortran was required to link openblas), e.g, libgfortran.so.5 was actually linked to the binary if using ldd binary, together with libquadmath.so.0. I am wondering whether gfortran can be linked statically by gcc.
Thanks,
Jianshu
I am wondering whether gfortran can be linked statically by gcc.
This is possible if libgfortran.a exists on your system. gfortran has a command line flag -static-libgfortran, but it does not work if libgfortran.a does not exist.
https://gcc.gnu.org/onlinedocs/gfortran/Link-Options.html
On systems that provide libgfortran as a shared and a static library, this option forces the use of the static version. If no shared version of libgfortran was built when the compiler was configured, this option has no effect.
On some Linux distribution, including ArchLinux which I usually use, gfortran package does not distribute static system libraries. Please use ubuntu or other distribution which distributes libgfortran.a.
static libgfortran.so link
Basically, it is not possible to link share library in static manner.
Strange enough,I have both static and dynamic libraries installed on my system. However rustc link dynamically gfortran and quadmath. is there a way to ask rustc link statically? i understand by default dynamic is better. but for portability of binaries,static is more convenient.
thanks,
Jianshu
I have both static and dynamic libraries installed on my system. However rustc link dynamically gfortran and quadmath.
This behavior should be fixed. I'll look into it.
It seems this question is related to gcc/gfotran (due to libquadmath not linked statically): https://stackoverflow.com/questions/17910684/static-libgfortran-in-library-build . It is the same on linux for me. On ubuntu like system, libgfortran.a and libquadmath.a are all installed after installing gcc/gfortran, they are just forced to link dynamically.
I have been struggling with this problem for several weeks.
Thanks,
Jianshu
Hello! Is there any solution to it? It really confuse me for times. Thanks @jianshu93 @termoshtt
I think still no. linux force dynamic link for library quadmath while gfortran relies on it. therefore libfortran.so will be used instead of .a
I found a temporary solution.
rustc can link libgfortran.a by cargo:rustc-link-lib=static=gfortran and cargo:rustc-link-search=path/to/- your/libgfortran.a at its link stage.
However, path/to/your/libgfortran.a is required because it's only in the search path of gcc/g++/gfortran...but not rustc.
the path of libgfortran.a can be get by ${PREFIX}-gfortran --print-file-name=libgfortran.a
but quadmath is still linked dynamically right. but still this is much better than before, at least gfortran is static now.
Thanks
Jianshu
and you can use the same way to the quadmath, it works
---- Replied Message ----
| From | @.> |
| Date | 03/16/2023 02:45 |
| To | @.> |
| Cc | @.>@.> |
| Subject | Re: [blas-lapack-rs/openblas-src] Link libgfortran statically when features=static (Issue #88) |
but quadmath is still linked dynamically right. but still this is much better than before, at least gfortran is static now.
Thanks
Jianshu
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
is there a easy way to add those to a configure file so that I do not need to worry about them next time? Thanks Jianshu
I have no idea.
I use ${PREFIX}-gfortran --print-file-name=libgfortran.a to get the path because different target has diferrent path of these libs.
Then, I use the following content in build.rs to link them
println!("cargo:rustc-link-lib=static=gfortran");
println!("cargo:rustc-link-search=path/to/your/libgfortran.a");
if cfg!(target_arch="x86_64") {
println!("cargo:rustc-link-lib=static=quadmath");
println!("cargo:rustc-link-search=path/to/your/libquadmath.a");
}
Maybe this method can be done in openblas-src
This does not work for me. Is that because I have both dynamic and static installed?
Thanks, Jianshu
I tried this method on Ubuntu22, which has both dynamic and static library, and it works.
I dont know why it doesn't work for you.
I'm sorry that I can't help you.
It turns out that I am on a linux server, which is annoying for building/linking/installing libraries.
I use your strategy and it compiles but the last step it complained that native static libgortran.a was not found despite I provide the search path for libgfortran.a as you did. I will test on a regular Linux system and get back.
Thanks,
Jianshu