diff --git a/cmake/unix/compiledata.sh b/cmake/unix/compiledata.sh index d3019aa786f94..238dc3e18587b 100755 --- a/cmake/unix/compiledata.sh +++ b/cmake/unix/compiledata.sh @@ -43,10 +43,6 @@ if [ "$ARCH" = "macosx" ] || [ "$ARCH" = "macosx64" ] || \ # If install_name is specified, remove it. SOFLAGS="$OPT -dynamiclib -single_module -Wl,-dead_strip_dylibs" fi - # Add rpath to the compiler options on MacOS, reproducing the same - # behaviour of manually creating the shared library by using the flags - # output by `root-config --libs` - SOFLAGS="$SOFLAGS -Wl,-rpath,$LIBDIR" elif [ "x`echo $SOFLAGS | grep -- '-soname,$'`" != "x" ]; then # If soname is specified, add the library name. SOFLAGS=$SOFLAGS\$LibName.$SOEXT @@ -121,7 +117,7 @@ echo "#define COMPILER \""`type -path $CXX`"\"" >> "${COMPILEDATA}.tmp" echo "#define COMPILERVERS \"$COMPILERVERS\"" >> "${COMPILEDATA}.tmp" echo "#define COMPILERVERSSTR \"$COMPILERVERSSTR\"" >> "${COMPILEDATA}.tmp" if [ "$CUSTOMSHARED" = "" ]; then - echo "#define MAKESHAREDLIB \"cd \$BuildDir ; $BXX -fPIC -c \$Opt $CXXFLAGS \$IncludePath \$SourceFiles ; $BXX \$Opt \$ObjectFiles $SOFLAGS $LDFLAGS $EXPLLINKLIBS -o \$SharedLib\"" >> "${COMPILEDATA}.tmp" + echo "#define MAKESHAREDLIB \"cd \$BuildDir ; $BXX -fPIC -c \$Opt $CXXFLAGS \$IncludePath \$SourceFiles ; $BXX \$Opt \$ObjectFiles $SOFLAGS $LDFLAGS \$RPath $EXPLLINKLIBS -o \$SharedLib \"" >> "${COMPILEDATA}.tmp" else echo "#define MAKESHAREDLIB \"$CUSTOMSHARED\"" >> "${COMPILEDATA}.tmp" fi diff --git a/core/base/src/TSystem.cxx b/core/base/src/TSystem.cxx index 42d29fac93c1a..018ea869ed8eb 100644 --- a/core/base/src/TSystem.cxx +++ b/core/base/src/TSystem.cxx @@ -3736,6 +3736,7 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt, cmd.ReplaceAll("\"$BuildDir","$BuildDir"); cmd.ReplaceAll("$BuildDir","\"$BuildDir\""); cmd.ReplaceAll("$BuildDir",build_loc); + cmd.ReplaceAll("$RPath", "-Wl,-rpath," + gROOT->GetSharedLibDir()); TString optdebFlags; if (mode & kDebug) optdebFlags = fFlagsDebug + " "; @@ -4133,7 +4134,7 @@ void TSystem::SetMakeExe(const char *directives) /// construct should be avoided. In particular this description can contain /// environment variables, like $ROOTSYS (or %ROOTSYS% on windows). /// ~~~ {.cpp} -/// Five special variables will be expanded before execution: +/// The following special variables will be expanded before execution: /// Variable name Expands to /// ------------- ---------- /// $SourceFiles Name of source files to be compiled @@ -4142,6 +4143,7 @@ void TSystem::SetMakeExe(const char *directives) /// $BuildDir Directory where the files will be created /// $IncludePath value of fIncludePath /// $LinkedLibs value of fLinkedLibs +/// $RPath ROOT's library directory is added as -rpath /// $DepLibs libraries on which this library depends on /// $ObjectFiles Name of source files to be compiler with /// their extension changed to .o or .obj @@ -4155,10 +4157,11 @@ void TSystem::SetMakeExe(const char *directives) /// --no_exceptions --signed_chars --display_error_number /// --diag_suppress 68 -o $SharedLib"); /// -/// gSystem->setMakeSharedLib( +/// // Or adding an rpath to the generated libraries (ROOT's rpath is inserted automatically into $RPath): +/// gSystem->SetMakeSharedLib( /// "Cxx $IncludePath -c $SourceFile; /// ld -L/usr/lib/cmplrs/cxx -rpath /usr/lib/cmplrs/cxx -expect_unresolved -/// \$Opt -shared /usr/lib/cmplrs/cc/crt0.o /usr/lib/cmplrs/cxx/_main.o +/// \$Opt \$RPath -shared /usr/lib/cmplrs/cc/crt0.o /usr/lib/cmplrs/cxx/_main.o /// -o $SharedLib $ObjectFile -lcxxstd -lcxx -lexc -lots -lc" /// /// gSystem->SetMakeSharedLib(