# Bug in \`RPATH\`/\`RUNPATH\` specification in \`CMakeLists.txt\`

**URL:** <https://openfhe.discourse.group/t/bug-in-rpath-runpath-specification-in-cmakelists-txt/1071>\
**Category:** Library Questions\
**Created:** [February 8, 2024, 5:52am UTC](https://openfhe.discourse.group/t/bug-in-rpath-runpath-specification-in-cmakelists-txt/1071 "2024-02-08T05:52:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sloede](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/sloede/32/198_2.png) [@sloede](https://openfhe.discourse.group/u/sloede)\
**Post date:** [February 8, 2024, 5:52am UTC](https://openfhe.discourse.group/t/bug-in-rpath-runpath-specification-in-cmakelists-txt/1071/1 "2024-02-08T05:52:06Z")

</div>

It seems to me like there is a bug in `CMakeLists.txt` with respect to the correct `RPATH` setting.

_Note: While this issue was detected and verified on Linux, it is likely it pertains also to macOS._

In

> <https://github.com/openfheorg/openfhe-development/blob/b2869aef5cf61afd364b3eaea748dcc8a7020b9c/CMakeLists.txt#L135>

the `CMAKE_INSTALL_RPATH` is set to `${LIBINSTALL}`. However, the `LIBINSTALL` variable is never set, which leaves all library products with an empty `RUNPATH`, as verified, e.g., by running

```shell
readelf -d path/to/install/prefix/lib/libOPENFHEpke.so | grep RUNPATH

```

and receiving an empty string.

This setting causes problems for applications that explicitly link only to `libOPENFHEpke.so` but not to `libOPENFHEbinfhe.so` and/or `libOPENFHEcore.so`, since `libOPENFHEbinfhe.so` is a dependency of `libOPENFHEpke.so`, and `libOPENFHEcore.so` is a dependency of both `libOPENFHEbinfhe.so` and `libOPENFHEbinfhe.so`:

```shell
$> readelf -d libOPENFHEbinfhe.so | grep NEEDED | grep OPENFHE
 0x0000000000000001 (NEEDED) Shared library: [libOPENFHEcore.so.1]
$> readelf -d libOPENFHEpke.so | grep NEEDED | grep OPENFHE
 0x0000000000000001 (NEEDED) Shared library: [libOPENFHEbinfhe.so.1]
 0x0000000000000001 (NEEDED) Shared library: [libOPENFHEcore.so.1]

```

Since the `RUNPATH` is not transitive, it means that a user application linking only to `libOPENFHEpke.so` will get load errors such as `libOPENFHEbinfhe.so.1: cannot open shared object file: No such file or directory`. The reason is that `libOPENFHEpke.so` needs `libOPENFHEbinfhe.so.1`, but cannot find it, since its `RUNPATH` is not set.

I have confirmed that adding

```cmake
set(LIBINSTALL "${CMAKE_INSTALL_PREFIX}/lib")

```

before the line `set(CMAKE_INSTALL_RPATH "${LIBINSTALL}")` in `CMakeLists.txt` would fix this problem, as confirmed by the existence of the `RUNPATH` entry in the relevant libraries, e.g.,

```shell
$> readelf -d ../install/lib/libOPENFHEpke.so | grep RUNPATH
 0x000000000000001d (RUNPATH) Library runpath: [/path/to/openfhe/install/prefix/lib]

```

If the solution approach is confirmed by the core developers, I’d be happy to create a PR to fix this.

cc @Arseniy

---

<div class="post-metadata">

**Author:** ![sloede](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/sloede/32/198_2.png) [@sloede](https://openfhe.discourse.group/u/sloede)\
**Post date:** [February 8, 2024, 6:37am UTC](https://openfhe.discourse.group/t/bug-in-rpath-runpath-specification-in-cmakelists-txt/1071/2 "2024-02-08T06:37:17Z")

</div>

For the time being, as a workaround you can amend the CMake command for OpenFHE without having to edit `CMakeLists.txt` directly. After cloning `openfhe-development`, create a `build` subdirectory, enter it, and call

```shell
cmake .. \
  -DCMAKE_INSTALL_PREFIX=/path/to/install/prefix \
  -DLIBINSTALL=/path/to/install/prefix/lib

```

---

<div class="post-metadata">

**Author:** ![dsuponitskiy-duality](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@dsuponitskiy-duality](https://openfhe.discourse.group/u/dsuponitskiy-duality)\
**Post date:** [February 12, 2024, 7:30pm UTC](https://openfhe.discourse.group/t/bug-in-rpath-runpath-specification-in-cmakelists-txt/1071/3 "2024-02-12T19:30:15Z")

</div>

[CMAKE\_INSTALL\_RPATH is not set correctly · Issue #670 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/issues/670) was created to address this issue

---

<div class="post-metadata">

**Author:** ![sloede](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/sloede/32/198_2.png) [@sloede](https://openfhe.discourse.group/u/sloede)\
**Post date:** [September 30, 2025, 6:00pm UTC](https://openfhe.discourse.group/t/bug-in-rpath-runpath-specification-in-cmakelists-txt/1071/4 "2025-09-30T18:00:18Z")

</div>

[Update CMakeLists.User.txt to remove need for LD\_LIBRARY\_PATH by dsuponitskiy · Pull Request #1056 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/pull/1056) Seems to have fixed it.
