# Dynamically Loaded Filters on Mac OS

**URL:** <https://forum.hdfgroup.org/t/dynamically-loaded-filters-on-mac-os/9159>\
**Category:** HDF5 Library\
**Created:** [November 11, 2021, 4:38pm UTC](https://forum.hdfgroup.org/t/dynamically-loaded-filters-on-mac-os/9159 "2021-11-11T16:38:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![howard](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@howard](https://forum.hdfgroup.org/u/howard)\
**Post date:** [November 11, 2021, 4:38pm UTC](https://forum.hdfgroup.org/t/dynamically-loaded-filters-on-mac-os/9159/1 "2021-11-11T16:38:35Z")

</div>

My desktop application uses HDF5 1.10.7 on Mac OS and Windows.

I succeeded in getting [dynamically loaded filters](https://support.hdfgroup.org/HDF5/doc1.8/Advanced/DynamicallyLoadedFilters/HDF5DynamicallyLoadedFilters.pdf) (a.k.a., plugins) to work on Windows using hdf5plugin-1.10.7-win10\_64-vs15.zip from [https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.7/plugins/](https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.7/plugins/)

I am not able to get them to work on Mac OS. I tried hdf5plugin-1.10.7-osx1013\_64-clang.tar.gz and hdf5plugin-1.10.7-osx1013\_64-intel.tar.gz. Both provided “.so” files (e.g., libh5blosc.so) but I believe on Macintosh I need .dylib files. I have not been able to find .dylib files.

I have installed the .so files in the right place ("/usr/local/hdf5/lib/plugin") but they are not found by the HDF5 library.

Even with hdf5plugin-1.10.7-osx1013\_64-clang.tar, the README file talks about Linux and Windows but nothing about Mac. So I’m starting to think that dynamically loaded filters are not supported on Mac.

Thanks in advance for any enlightenment.

---

<div class="post-metadata">

**Author:** ![miller86](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/miller86/32/124_2.png) [@miller86](https://forum.hdfgroup.org/u/miller86)\
**Post date:** [November 11, 2021, 5:23pm UTC](https://forum.hdfgroup.org/t/dynamically-loaded-filters-on-mac-os/9159/2 "2021-11-11T17:23:15Z")

</div>

I run on mac too (macOS 10.14) and I would not say that .dylib files are a _requirement_. That is the macOS native way of doing shared libs but I’ve used .so files for HDF5 plugins fine on macOS.

Have you used the HDF5\_PLUGIN\_PATH environment variable to inform HDF5 library where to go look for plugins? Also, if you set the HDF5\_DEBUG environment variable ([https://support.hdfgroup.org/HDF5/doc/H5.user/Debugging.html](https://support.hdfgroup.org/HDF5/doc/H5.user/Debugging.html)) to “all”, you might get some hints from the library about why its not finding your plugin shared libs.

---

<div class="post-metadata">

**Author:** ![howard](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@howard](https://forum.hdfgroup.org/u/howard)\
**Post date:** [November 11, 2021, 8:34pm UTC](https://forum.hdfgroup.org/t/dynamically-loaded-filters-on-mac-os/9159/3 "2021-11-11T20:34:21Z")

</div>

Thanks. This was useful.

My program has a command that dumps collected HDF5 library error messages. Using this I saw:

> \_While executing HDF5LoadData, H5Dread failed. (HDF5 Library Error -1)  
> \_HDF5 library function H5PL\_\_open(): can’t dlopen:dlopen(/usr/local/hdf5/lib/plugin/libh5blosc.so, 5): Library not loaded: @rpath/libhdf5.103.dylib  
> \_ Referenced from: /usr/local/hdf5/lib/plugin/libh5blosc.so  
> \_ Reason: image not found

From that I can tell that the Mac dynamic loader _is_ trying to load the .so file and that the .so file is looking for a library named libhdf5.103.dylib.

My application ships with a library named libhdf5.dylib in the Frameworks folder of the application bundle. After about two hours of floundering and trial-and-error (with rpath and loader\_path), I finally found the magic incantation:

> install\_name\_tool -change “@rpath/libhdf5.103.dylib” “@executable\_path/…/Frameworks/libhdf5.dylib” “/usr/local/hdf5/lib/plugin/libh5blosc.so”

This tells libh5blosc.so to look for hdf5lib.dylib in the Frameworks folder of the bundle of the currently-running application. And it worked!

I did this for all of the .so files in /usr/local/hdf5/lib/plugin using this command:

> for file in /usr/local/hdf5/lib/plugin/\*.so; do install\_name\_tool -change “@rpath/libhdf5.103.dylib” “@executable\_path/…/Frameworks/libhdf5.dylib” “$file”; done

Thanks miller86!

---

<div class="post-metadata">

**Author:** ![howard](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@howard](https://forum.hdfgroup.org/u/howard)\
**Post date:** [November 11, 2021, 10:48pm UTC](https://forum.hdfgroup.org/t/dynamically-loaded-filters-on-mac-os/9159/4 "2021-11-11T22:48:50Z")

</div>

I verified that my solution works on Mac OS 10.14.6 (Mojave) and 12.0.1 (Monterey).

---

<div class="post-metadata">

**Author:** ![howard](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@howard](https://forum.hdfgroup.org/u/howard)\
**Post date:** [November 12, 2021, 12:10pm UTC](https://forum.hdfgroup.org/t/dynamically-loaded-filters-on-mac-os/9159/5 "2021-11-12T12:10:19Z")

</div>

To tie up one loose end…

On Unix a .so file is an [ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) file.

I believe that Macintosh can not use Linux ELF files but instead uses [Mach-O](https://en.wikipedia.org/wiki/Mach-O) files.

As explained [here](https://stackoverflow.com/questions/2339679/what-are-the-differences-between-so-and-dylib-on-macos):

> Loadable modules are called “bundles” in Mach-O speak. They have the file type MH\_BUNDLE. They can carry any extension; the extension .bundle is recommended by Apple, but most ported software uses .so for the sake of compatibility.

So a .so file that runs on Macintosh is a Mach-O file despite the fact that .so on Unix is an ELF file.

The command “otool -hv” reports the filetype of HDF5 dynamically loaded filter files (e.g., libh5blosc.so) as BUNDLE. This stands for MH\_BUNDLE which is described in the Mach-O loader.h file as “dynamically bound bundle file”.

To make matters more confusing, this type of bundle is not the same as a [CFBundle](https://en.wikipedia.org/wiki/Bundle_(macOS)) which is “is a file directory with a defined structure and file extension, allowing related files to be grouped together as a conceptually single item”.
