Let me first set the context, it is CERN's ROOT and CINT and ACLiC etc.
Suppose I have a main macro
named macro.cpp
and two headers h1.cpp
(contains the definition of a function) and h1.h
containing the declaration of the function defined in h1.cpp
similarly I have h2.cpp
and h2.h
. The main program macro.cpp
calls those functions inside h1
and h2
. I was successful compiling the source files using:
root [0] .L h1.cpp+
root [1] .L h2.cpp+
root [2] .L macro.cpp+
which generated three .so
files macro_cpp.so
, h1_cpp.so
and h2_cpp.so
. I want to know what to do with them ? How do I link
them so that I have something like a "macro.out
" or something like that (a single executable
file of some kind) which I can execute (although I don't know how !) and achieve whatever I wished to achieve with the macro.
Note: If I just load all the files using .L file_name.cpp
etc and just execute the main macro using .x macro.cpp
then everything works fine and I have results, but this is not what I want ! I want to compile like we do in usual g++
and by the way in every forum everyone keeps advising on compiling using .L file_name.cpp+
or ++
.. I would really like to know the whole story. Because nobody seems to explain beyond .L file_name.cpp+
.. what next ? What to do with the .so
etc.
I am a beginner, I will really appreciate a simple and step by step answer and explanation.
Thanks.
Edit-1: I am working with:
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Edit-2: ROOT related information: ROOT 5.34/36 (v5-34-36@v5-34-36, dic 07 2016, 23:31:51 on linuxx8664gcc) CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
If you want to compile and link you can use a standard compiler instead of Cint/Aclic. For example, assuming you are working on a *nix platform, you can use the example files below:
h1.h
h1.cpp
h2.h
h2.cpp
macro.cpp
Then you can compile with
and link with
The executable will be
a.out
:You can put these
g++
commands in a script or, when you start having several files and directories, you can write your make file (or cmake). For this last step, see for example the tutorial herehttp://www-pnp.physics.ox.ac.uk/~brisbane/Teaching/Makefiles/Tutorial_1_Makefiles_and_ROOT.pdf
Note 1: one advantage of using
g++
is that you will get clear error messages when something doesn't compile. The error messages from Cint can be difficult to understand--although this is very much improved in root 6 with Cling.Note 2: another advantage of using a standard compiler is that you will be able to easily link your main executable against libraries other than root.