Build HDF5 Filter Plugins on Linux Using MATLAB HDF5 Shared Library or GNU Export Map

35 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team about 17 hours ago
Edited: MathWorks Support Team less than a minute ago
Starting in R2021b, if you are working with HDF5 Dynamically Loaded Filters on Linux and if your filter plugin contains callbacks to the core HDF5 library (requires header hdf5.h), then you need to rebuild your filter plugin with the symbol-versioned HDF5 library that corresponds to your MATLAB release. You can find which version of the HDF5 library your MATLAB release uses by running the following:
[major,minor,relnum] = H5.get_libversion()
You can download HDF5 plugins (for the same version of HDF5 as in MATLAB) from https://github.com/HDFGroup/hdf5_plugins/releases.
To rebuild your filter plugin using standard Linux "configure/make/make install" build commands, use one of the options below.
Option 1 (preferred): Build the plugin using the HDF5 library shipped with MATLAB (e.g., libhdf5.so.x.x.x in /matlab/bin/glnxa64).
a. Obtain the HDF5 header files of the relevant HDF5 version from The HDF Group (e.g., hdf5-1.14.4-3-ubuntu-2204_gcc.tar.gz from https://github.com/HDFGroup/hdf5/releases/tag/hdf5_1.14.4.3, which provides header files in /hdf5/HDF5-1.14.4.3-Linux/HDF_Group/HDF5/1.14.4.3/include). Use the path to the header file as PATH_TO_HDF5_INCLUDEDIR.
b. Use /matlab/bin/glnxa64 as PATH_TO_HDF5_LIBDIR. If there isn't a libhdf5.so file but a file with a numeric suffix instead (e.g., libhdf5.so.310), you need to create a symbolic link  libhdf5.so that points to the suffixed file.
c. You will need the relevant compression algorithm library installed. For example, when building the HDF5 BZIP2 Filter Plugin on Linux, you need to specify the location of the bzip2 compression algorithm binary libbz2.so.*, which is typically located in /usr/lib/. Set up CPPFLAGS to contain paths to the header files (for HDF5 and for the compression library), and LDFLAGS to contain paths to the binaries (for HDF5 and for the compression library as well) 
setenv CPPFLAGS "-I<PATH_TO_COMPRESSION_INCLUDEDIR> -I<PATH_TO_HDF5_INCLUDEDIR>"
setenv LDFLAGS "-L<PATH_TO_COMPRESSION_LIBDIR> -L/<PATH_TO_HDF5_LIBDIR>"
d. In the hdf5_plugin source code folder, navigate to the plugin you want to build (e.g., BLOSC) and run the following to create a configure script from configure.am
autoreconf -i
e. Create and navigate to the build folder. Run configure from there, which creates the Makefile 
mkdir build
cd build
../configure
Then run make, which creates the binary for the plugin (e.g., libh5blosc.so.0.0.0 in the hdf5_plugins-hdf5-1.14.6/BLOSC/build/src/.libs folder).
Option 2:
Build relevant HDF5 library from source using the GNU Export Map to add symbol-versioning to the resultant binary.
a. Download the HDF5 Export Map text file for the relevant version of the HDF5 library (attached to this answer).
b. Set LDFLAGS to point to the map, for example (for 1.10.7)
LDFLAGS += -Wl,--version-script=hdf5_1_10_7_linux_exported_symbol.map
Then build the HDF5 library.
c. When building the filter plugin, specify the path to the resultant shared library from step b as LIBRDIR.
With either option, to ensure the MATLAB HDF5 version string (MWHDF5) is embedded in any callbacks to HDF5, you can check the dynamic symbol table in your plugin shared library using readelf or objdump. For example, if the plugin has a call to H5Pcreate, then the symbol entry should show the MWHDF5 symbol decoration.  See the following examples:
readelf -Ws <plugin.so>
H5Pcreate@@MWHDF5 0000000000000000 0 FUNC GLOBAL DEFAULT UND H5Pcreate@MWHDF5
objdump -C -T <plugin.so>
0000000000000000 DF *UND* 0000000000000000 MWHDF5 H5Pcreate

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!