Hi Jed, Satish,

Thank you both for your insights.

I think Jed is right -- it seems this would require changes in PETSc's build tools and scripts.

On our side, the CMake modification we made was along these lines:

SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../lib/${LIB_BUILD_TYPE}")

However, it's unclear to me how this approach would work for all of PETSc’s external packages. Can they also be relocated using $ORIGIN, or would they need a different solution? I suspect many libraries might not support this mechanism.

In any case, you’ve answered my question -- thank you again for your help!

Best,
Eric

On 2025-02-24 12:13, Jed Brown wrote:
I think fixing up the build tools would be more reliable. We can't change paths 
for libraries that are not installed in the same directory as libpetsc.so. What 
if we just substituted (perhaps only in the Makefile) $ORIGIN for the 
$PETSC_DIR/$PETSC_ARCH/lib prefix?

Satish Balay <balay....@fastmail.org> writes:

I see you are referring to 
https://urldefense.us/v3/__https://www.baeldung.com/linux/rpath-change-in-binary__;!!G_uCfscf7eWS!f7FgqvyBSVkObSDsRA2uRpI9SqxQm_45esiwkTgdj0eKkrGQn5C-j-bU-DR-T7stFHid-jUbqwu9_gXjsiU_4KPp7pg$

I suspect its easier to do this  by "manually modifying the libraries after their 
creation" than fix up build tools to support it.

configure accepts 'LIBS' option that can potentially be used - but I suspect 
the '$ORIGIN' might not survive different layers
of shell escapes that might occur.

./configure LIBS=-Wl,-rpath,'$ORIGIN'/foo1

Satish

On Mon, 24 Feb 2025, Eric Chamberland via petsc-users wrote:

Hello,

We would like to make the libraries generated from PETSc compilation and
installation more easily relocatable. Currently, we work around this
limitation by using LD_LIBRARY_PATH in the environment and manually modifying
the RPATH recorded in the libraries to remove it.

Recently, we discovered an interesting approach: during the build process, we
can set a relative RPATH using the $ORIGIN variable, which corresponds to the
directory containing the library. This allows libpetsc.so dependencies to be
referenced relatively instead of absolutely, making the library "movable"
without requiring LD_LIBRARY_PATH modifications. We can also apply the same
approach to our binaries.

To avoid manually modifying the libraries after their creation, we were
wondering if there is a way to configure PETSc to use a relative RPATH with
$ORIGIN directly?

I looked through PETSc's configuration options and files but couldn't find
anything mentioning $ORIGIN, and very little related to RPATH.

A SPACK newbie question: is this achievable with SPACK?

Thanks in advance for your help!

Eric


--
Eric Chamberland, ing., M. Ing
Professionnel de recherche
GIREF/Université Laval
(418) 656-2131 poste 41 22 42

Reply via email to