# Faster way to Load Libraries and Precompile .cpp files?

**URL:** <https://root-forum.cern.ch/t/faster-way-to-load-libraries-and-precompile-cpp-files/47698>\
**Category:** Newbie\
**Tags:** root\
**Created:** [November 17, 2021, 11:50am UTC](https://root-forum.cern.ch/t/faster-way-to-load-libraries-and-precompile-cpp-files/47698 "2021-11-17T11:50:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://root-forum.cern.ch/u/andrew)\
**Post date:** [November 17, 2021, 11:50am UTC](https://root-forum.cern.ch/t/faster-way-to-load-libraries-and-precompile-cpp-files/47698/1 "2021-11-17T11:50:33Z")

</div>

Hi everyone,

In order for my macros to run properly on ROOT, I have to load a library and compile a .cpp file (that defines class functions of a .hpp header). I don’t like to launch ROOT and load both manually everytime with

```auto
.L /path/to/lib/library.so
.L /path/to/file.cpp+

```

so what I have done instead is define an alias in my `.bashrc` file, which goes like:

```auto
alias roott='root -l -L /path/to/lib/library.so -L ~/path/to/file.cpp+'

```

This all works really well and I am generally happy. However, whenever I launch `roott`, it takes (and reasonably so) a while to compile (~15 seconds) and sometimes it becomes quite annoying, particularly when I am exiting ROOT to make a small amend and come back in. Is there any workaround that will make things a bit faster?

Thank you,

Andy

* * *

\_ROOT Version: 6.24/06  
\_Platform: Centos08  
\_Compiler: g++ (GCC) 11.1.0

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 17, 2021, 2:05pm UTC](https://root-forum.cern.ch/t/faster-way-to-load-libraries-and-precompile-cpp-files/47698/2 "2021-11-17T14:05:37Z")

</div>

> [@andrew](#):
>
> ```auto
> .L /path/to/lib/library.so
> .L /path/to/file.cpp+
> 
> ```

You can also put the two commands in your `rootlogon.C` file.  
`file.cpp+` is some C++ code. `.L /path/to/file.cpp+` will compile it.  
May be compile it once and load the `.so` as you do for `library.so`

---

<div class="post-metadata">

**Author:** ![andrew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://root-forum.cern.ch/u/andrew)\
**Post date:** [November 17, 2021, 3:15pm UTC](https://root-forum.cern.ch/t/faster-way-to-load-libraries-and-precompile-cpp-files/47698/3 "2021-11-17T15:15:04Z")

</div>

Thank you a lot for the reply,

The `.L` inside the `rootlogon.C` does not seem to work. However,

```auto
gSystem->Load("/path/to/lib/library.so"); 

```

seems to be working flawlessly. This however does not resolve the compilation of the `file.cpp`. I tried:

```auto
gSystem->Load("/path/to/file.cpp+");

```

and I got:

```auto
Error in <TUnixSystem::FindDynamicLibrary>: /home/andreas/ROOTScripts/Classes/Cluster.cpp+[.so | .dll | .dylib | .sl | .dl | .a] does not exist in /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.24.06-20127/x86_64-centos8-gcc11-opt/lib:/cvmfs/clicdp.cern.ch/software/allpix-squared/latest/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/LCIO/02.16.01-acee3/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.36.1-a9696/x86_64-centos8/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib64:/cvmfs/sft.cern.ch/lcg/releases/MCGenerators/thepeg/2.2.1-aa9c8/x86_64-centos8-gcc11-opt/lib/ThePEG:/cvmfs/sft.cern.ch/lcg/releases/MCGenerators/herwig++/7.2.1-70ec3/x86_64-centos8-gcc11-opt/lib/Herwig:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos8-gcc11-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.36.1-a9696/x86_64-centos8/lib:/cvmfs/clicdp.cern.ch/software/ROOT/6.12.06/x86_64-centos7-gcc8-opt/lib:/cvmfs/clicdp.cern.ch/software/allpix-squared/latest/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/LCIO/02.16.01-acee3/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.36.1-a9696/x86_64-centos8/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib64:/cvmfs/sft.cern.ch/lcg/releases/MCGenerators/thepeg/2.2.1-aa9c8/x86_64-centos8-gcc11-opt/lib/ThePEG:/cvmfs/sft.cern.ch/lcg/releases/MCGenerators/herwig++/7.2.1-70ec3/x86_64-centos8-gcc11-opt/lib/Herwig:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib/python3.9/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos8-gcc11-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/11.1.0-e80bf/x86_64-centos8/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.36.1-a9696/x86_64-centos8/lib:/cvmfs/clicdp.cern.ch/software/ROOT/6.12.06/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-e7560/x86_64-centos8-gcc11-opt/lib64/R/library/readr/rcon:/cvmfs/sft.cern.ch/lcg/releases/clhep/2.4.4.0-b903d/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/XercesC/3.2.3-714f6/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-e7560/x86_64-centos8-gcc11-opt/lib64/R/library/readr/rcon:/cvmfs/sft.cern.ch/lcg/releases/clhep/2.4.4.0-b903d/x86_64-centos8-gcc11-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/XercesC/3.2.3-714f6/x86_64-centos8-gcc11-opt/lib:.:/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.24.06-20127/x86_64-centos8-gcc11-opt/lib:/lib64/glibc-hwcaps/x86-64-v4:/lib64/glibc-hwcaps/x86-64-v3:/lib64/glibc-hwcaps/x86-64-v2:/lib64/tls/haswell/avx512_1/x86_64:/lib64/tls/haswell/avx512_1:/lib64/tls/haswell/x86_64:/lib64/tls/haswell:/lib64/tls/avx512_1/x86_64:/lib64/tls/avx512_1:/lib64/tls/x86_64:/lib64/tls:/lib64/haswell/avx512_1/x86_64:/lib64/haswell/avx512_1:/lib64/haswell/x86_64:/lib64/haswell:/lib64/avx512_1/x86_64:/lib64/avx512_1:/lib64/x86_64:/lib64:/usr/lib64/glibc-hwcaps/x86-64-v4:/usr/lib64/glibc-hwcaps/x86-64-v3:/usr/lib64/glibc-hwcaps/x86-64-v2:/usr/lib64/tls/haswell/avx512_1/x86_64:/usr/lib64/tls/haswell/avx512_1:/usr/lib64/tls/haswell/x86_64:/usr/lib64/tls/haswell:/usr/lib64/tls/avx512_1/x86_64:/usr/lib64/tls/avx512_1:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/haswell/avx512_1/x86_64:/usr/lib64/haswell/avx512_1:/usr/lib64/haswell/x86_64:/usr/lib64/haswell:/usr/lib64/avx512_1/x86_64:/usr/lib64/avx512_1:/usr/lib64/x86_64:/usr/lib64

```

Changing it to:

```auto
gSystem->Load("/path/to/file.cpp");

```

Makes the error disappear, but when I run a file that uses functions defined there, I get an undefined symbol error:

```auto
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.24.06-20127/x86_64-centos8-gcc11-opt/bin/root.exe: symbol lookup error: /path/to/Macro_cpp.so: undefined symbol: _ZN8ClustersC1ESt6vectorIPN6allpix8PixelHitESaIS3_EE

```

Any possible workaround/solution to this?

Thank you,

Andy

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 17, 2021, 3:17pm UTC](https://root-forum.cern.ch/t/faster-way-to-load-libraries-and-precompile-cpp-files/47698/4 "2021-11-17T15:17:43Z")

</div>

Can you compile `file.cpp` outside ROOT and do:

```auto
gSystem->Load("/path/to/file.so");

```

Instead of loading the `.cpp` file ?

---

<div class="post-metadata">

**Author:** ![andrew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://root-forum.cern.ch/u/andrew)\
**Post date:** [November 17, 2021, 3:40pm UTC](https://root-forum.cern.ch/t/faster-way-to-load-libraries-and-precompile-cpp-files/47698/5 "2021-11-17T15:40:52Z")

</div>

Hi,

Yes, this works flawlessly and everything runs as expected. Sorry, I didn’t see it the .so for `file.cpp` in the first answer. Thank you very much!

Andy
