I recently discovered that the HDF5 tools prefer to be linked with the static HDF5 library when building HDF5 with CMake on Linux. This differ from the configure
default behavior.
If I do not specify anything special, both CMake and configure
build both static and shared libraries. This is fine. But the tools like h5diff
, h5dump
etc. link against the static libraries when built with CMake, and against the shared ones when built with configure
.
If I set the -DONLY_SHARED_LIBS=ON
when running CMake, then only dynamic libraries are built, and the tools of course link against the dynamic libraries… But then the tools are renamed from “h5diff” to “h5diff-shared”!!! Why???
The effect in file size between the two options are dramatic - when using dynamic linking h5diff
is 215 kB and h5dump
is 443 kB - and when using static linking they are 16 MB each. I pack HDF5 into a redistribute package where size matters and the HDF5 tools alone are ~220 MB!
I do not need the static libraries for any particular purpose - so I am happy setting -DONLY_SHARED_LIBS=ON
. But the fact that the tools are renamed and get a -shared
extension is very cumbersome. I would manually need to rename them or make some symlinks in there for this to work.
This behavior is sort of documented in the bottom of release_docs/RELEASE.txt.
I still wonder about the rationale for these decisions. I like CMake because it is usually very good in picking up compiler flags, link paths etc. It has supported building HDF5 with the new LLVM-based Intel compilers (icx
, ifx
) for a long time and way before these compilers could be used with the configure
script. HDF5 1.14.0 still only builds with these compilers using CMake, not configure
, so configure
is not really an option.
Could there be any options for building these tools in the same way across both configure
and CMake? Why is the suffix -shared
needed? Is there any workaround besides manually renaming the binaries after “make install”?
I appreciate all comments. Thanks.