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
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
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:
$> 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
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.,
$> 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