# Trouble with RPATH when building netcdf for Fedora

**URL:** https://discourse.cmake.org/t/trouble-with-rpath-when-building-netcdf-for-fedora/15532
**Category:** Code
**Tags:** os:linux
**Created:** [February 27, 2026, 4:11am UTC](https://discourse.cmake.org/t/trouble-with-rpath-when-building-netcdf-for-fedora/15532 "2026-02-27T04:11:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![opoplawski](https://discourse.cmake.org/user_avatar/discourse.cmake.org/opoplawski/32/3829_2.png) [@opoplawski](https://discourse.cmake.org/u/opoplawski)
#### Post date: [February 27, 2026, 4:11am UTC](https://discourse.cmake.org/t/trouble-with-rpath-when-building-netcdf-for-fedora/15532/1 "2026-02-27T04:11:32Z")

</div>

I package netcdf for Fedora. I’m working on switching to cmake for building the project and having trouble with RPATHs ending up in installed files. Fedora forbids rpath in installed files. I get the following messages:

```auto
ERROR 0002: file '/usr/lib64/openmpi/hdf5/plugin/lib__nczhdf5filters.so' contains an invalid runpath '/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-openmpi' in [/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-openmpi:/usr/lib64/openmpi/lib]
ERROR 0002: file '/usr/lib64/mpich/hdf5/plugin/lib__nczhdf5filters.so' contains an invalid runpath '/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-mpich' in [/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-mpich:/usr/lib64/mpich/lib]
ERROR 0002: file '/usr/lib64/openmpi/hdf5/plugin/lib__nczstdfilters.so' contains an invalid runpath '/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-openmpi' in [/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-openmpi:/usr/lib64/openmpi/lib]
ERROR 0002: file '/usr/lib64/mpich/hdf5/plugin/lib__nczstdfilters.so' contains an invalid runpath '/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-mpich' in [/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-mpich:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/nccopy' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/ncdump' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/ncgen3' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/mpich/bin/nccopy' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/ncgen' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/mpich/bin/ncdump' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/mpich/bin/ncgen3' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0002: file '/usr/lib64/hdf5/plugin/lib__nczhdf5filters.so' contains an invalid runpath '/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-serial' in [/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-serial]
ERROR 0010: file '/usr/lib64/mpich/bin/ncgen' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0002: file '/usr/lib64/hdf5/plugin/lib__nczstdfilters.so' contains an invalid runpath '/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-serial' in [/home/orion/fedora/netcdf/netcdf-4.9.3-build/netcdf-c-main/redhat-linux-build-serial]

```

So basically two types of files - utilities and plugin libraries. I’ve tried to avoid this by specifying `-DCMAKE_SKIP_INSTALL_RPATH=ON` but that had no effect.

netcdf has the following RPATH code:

```auto
if(NOT WIN32 AND BUILD_SHARED_LIBS)
  # use, i.e. don't skip the full RPATH for the build tree
  set(CMAKE_SKIP_BUILD_RPATH FALSE)

  # when building, don't use the install RPATH already
  # (but later on when installing)
  set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

  if(APPLE)
    set(CMAKE_MACOSX_RPATH ON)
  endif(APPLE)

  # add the automatically determined parts of the RPATH
  # which point to directories outside the build tree to the install RPATH
  # set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

  # the RPATH to be used when installing,
  # but only if it's not a system directory
  list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
  if("${isSystemDir}" STREQUAL "-1")
    set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
  endif("${isSystemDir}" STREQUAL "-1")

endif()

```

So I guess I would expect `CMAKE_INSTALL_RPATH` to get set for the MPI builds, and this seems to hold for utilities. But my expectation is that setting `CMAKE_SKIP_INSTALL_RPATH` would have overriden it.

The plugins are currently installed with:

```auto
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${INSTALLED_PLUGIN_LIB} DESTINATION ${NETCDF_PLUGIN_INSTALL_DIR})

```

And I presume it’s the use of `PROGRAMS` that is the problem with the plugins installed in the serial build. I’ve changed that to:

```auto
install(TARGETS ${PRLUGINPRE}${PLUG} DESTINATION ${NETCDF_PLUGIN_INSTALL_DIR})

```

and removed the `CMAKE_INSTALL_RPATH` in CMakeLists.txt. That did get rid of the rpath in the serial build plugins, but did nothing for the MPI utilities. So I’m down to:

```auto
ERROR 0010: file '/usr/lib64/openmpi/hdf5/plugin/lib__nczhdf5filters.so' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/mpich/hdf5/plugin/lib__nczhdf5filters.so' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/openmpi/hdf5/plugin/lib__nczstdfilters.so' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/mpich/hdf5/plugin/lib__nczstdfilters.so' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/nccopy' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/ncdump' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/ncgen3' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/openmpi/bin/ncgen' contains an empty runpath in [:/usr/lib64/openmpi/lib]
ERROR 0010: file '/usr/lib64/mpich/bin/nccopy' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/mpich/bin/ncdump' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/mpich/bin/ncgen3' contains an empty runpath in [:/usr/lib64/mpich/lib]
ERROR 0010: file '/usr/lib64/mpich/bin/ncgen' contains an empty runpath in [:/usr/lib64/mpich/lib]

```

I’m also not sure why only these two plugins have the rpath - but I think probably because they are the only two that are linked to the netcdf library.

Can someone tell me how to prevent these rpaths from remaining in the installed files?

---

<div class="post-metadata">

### Author: ![AnthonyD973](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anthonyd973/32/3130_2.png) [@AnthonyD973](https://discourse.cmake.org/u/AnthonyD973)
#### Post date: [March 3, 2026, 2:09pm UTC](https://discourse.cmake.org/t/trouble-with-rpath-when-building-netcdf-for-fedora/15532/2 "2026-03-03T14:09:11Z")

</div>

I haven’t encountered this exact error before, and a quick search for “contains an invalid runpath” doesn’t show anyone else coming up with that. Are you sure the error comes from CMake?

Either way, I think it’s unusual to specify an absolute path in your RPATH. You should probably specify `$ORIGIN`in your RPATH instead so that shared libraries and executables can find each other based on their own location. [Here’s some example code of mine showing how to do that](https://github.com/adentinger/CMakeBestPractices/blob/404d8bedf67aff29f653adf889f0944bb3b6434d/prj2/lib2/CMakeLists.txt#L152).

---

<div class="post-metadata">

### Author: ![opoplawski](https://discourse.cmake.org/user_avatar/discourse.cmake.org/opoplawski/32/3829_2.png) [@opoplawski](https://discourse.cmake.org/u/opoplawski)
#### Post date: [March 4, 2026, 12:30am UTC](https://discourse.cmake.org/t/trouble-with-rpath-when-building-netcdf-for-fedora/15532/3 "2026-03-04T00:30:26Z")

</div>

The error messages don’t come from cmake, they come from Fedora’s RPM checks.

And I don’t want an RPATH based on $ORIGIN - I don’t want any RPATHs at all. What I don’t understand is why cmake is not removing the RPATHs on install as I expect it to (and it does for most items).
