I need to include separate libraries to the root. This is the Library ("wget https://www.vtk.org/files/release/9.0/VTK-9.0.1.tar.gz"). So I tried to install it using the following steps.
In my build directory I found lib64, There are so many libraries. I can load just one library, but how can load all libraries? Here are few libraries in the lib64
Create a simple “rootlogon.C” file (in your current working directory):
{ // rootlogon.C
gInterpreter->AddIncludePath("/where/are/your/VTK/includes");
gSystem->AddDynamicPath("/where/are/your/VTK/libs");
// load all "libvtk*.so" shared libraries (no need to append ".so" in names)
// note: if they depend on one another, the order matters; e.g., try to
// load them in the same order as they had been built: "ls -1rt libvtk*.so"
gSystem->Load("libvtkCommonColor-9.0");
gSystem->Load("libvtkFiltersSources-9.0");
gSystem->Load("libvtklz4-9.0");
// ...
gSystem->Load("libvtkpng-9.0");
gSystem->Load("libvtkCommonMisc-9.0");
gSystem->Load("libvtkImagingGeneral-9.0");
}
You probably do not need to load all “libvtk*.so” libraries one by one. There are probably only several “top-level” libraries that you need to load “manually”. When they were being built, each of these “top-level” libraries was linked against “lower-level” libraries on which it depends. So, when you load such a “top-level” library, the system will automatically load all required “lower-level” libraries (that it knows about, of course).
Note however that, due to a known cling::DynamicLibraryManager deficiency, you need to add the “/where/are/your/VTK/libs” directory into the “LD_LIBRARY_PATH” environment variable (before starting root), or you need to run (just once): patchelf --set-rpath "\$ORIGIN" /where/are/your/VTK/libs/libvtk*.so
With the “rootlogon.C” file (in your current working directory) given below, one should be able to run all “VTK-9.0.x/Examples/Tutorial/Step*/Cxx/Cone*.cxx” in ROOT 6, e.g., as “interpreted” C++ macros:
{ // rootlogon.C ...
{ // VTK-9.0.x ...
// it is assumed that the VTK-9.0.x has been built using something like this:
// mkdir /path/to/build/dir/VTK-9.0.x; cd /path/to/build/dir/VTK-9.0.x
// cmake -DCMAKE_INSTALL_PREFIX=${HOME}/work/VTK/VTK-9.0 /path/to/source/dir/VTK-9.0.x
// make install # build and then install everything in "CMAKE_INSTALL_PREFIX"
// patchelf --set-rpath "\$ORIGIN" ${HOME}/work/VTK/VTK-9.0/lib*/libvtk*.so # set "RUNPATH"
TString prefix = "${HOME}/work/VTK/VTK-9.0"; // same as "CMAKE_INSTALL_PREFIX"
TString lib = "lib"; // "lib" or "lib64" (usually depends on the architecture)
TString version = "-9.0"; // e.g., "" or "-9.0" (note: it's without the "patch version" here)
if (!prefix.EndsWith("/")) prefix += "/";
gSystem->SetDynamicPath(gSystem->ExpandPathName(prefix + lib + ":") + TString(gSystem->GetDynamicPath()));
gInterpreter->AddIncludePath(gSystem->ExpandPathName(prefix + "include/vtk" + version));
#if 0 /* 0 or 1 */
// these environment variables may be needed if one plans to execute shell commands from inside of a ROOT session
gSystem->Setenv("LD_LIBRARY_PATH", gSystem->ExpandPathName(prefix + lib + ":") + TString(gSystem->Getenv("LD_LIBRARY_PATH")));
gSystem->Setenv("PATH", gSystem->ExpandPathName(prefix + "bin:") + TString(gSystem->Getenv("PATH")));
TString python = "python2.7"; // e.g., "python2.7" or "python3.8"
// TPRegexp(".*PYTHON_VERSION_MAJOR=([0-9]*).+PYTHON_VERSION_MINOR=([0-9]*).*").Substitute(python = gROOT->GetConfigOptions(), "python$1.$2");
gSystem->Setenv("PYTHONPATH", gSystem->ExpandPathName(prefix + lib + "/" + python + "/site-packages:") + TString(gSystem->Getenv("PYTHONPATH")));
#endif /* 0 or 1 */
// these VTK components are needed to run all "VTK-9.0.x/Examples/Tutorial/Step*/Cxx/Cone*.cxx"
std::vector<TString> components
{ "CommonCore",
"FiltersSources",
"InteractionStyle",
"InteractionWidgets", // needed by "Step6/Cxx/Cone6.cxx" only
"RenderingOpenGL2" };
// load the corresponding shared libraries
for (unsigned long i = 0; i < components.size(); i++) {
TString l = gSystem->ExpandPathName("libvtk" + components[i] + version);
int v = gSystem->Load(l);
if (v < 0) std::cout << "Warning: cannot load " << l << " : " << v << std::endl;
}
// initialize VTK components (i.e., these which need it)
if (!(gInterpreter->IsLoaded("vtkAutoInit.h")))
gInterpreter->ProcessLine("#include \"vtkAutoInit.h\"");
for (unsigned long i = 0; i < components.size(); i++) {
TString m = "vtk" + components[i];
gInterpreter->Declare("VTK_AUTOINIT_DECLARE(" + m + ");");
if (gSystem->DynFindSymbol(nullptr, gInterpreter->GetMangledName(0, m + "_AutoInit_Construct", "")))
gInterpreter->Declare("VTK_MODULE_INIT(" + m + ");");
}
} // ... VTK-9.0.x
} // ... rootlogon.C