Compiling multiple files

Hello all,

I have written some classes which I have turned into a shared library called TParticle.so .

Additionally, I have somewhat long, mostly C macro which I usually compile and execute in the following manner:

root [0] .L TParticle.so
root [1] .L doit.cpp+
root [2] doit(100, 100) , where my function takes two integers.

In any case, my macro has become much too long and I wish to break it up into several files, such as :

   doit.cpp
   helper1.h 
   helper2.h
   helper1.cpp
   helper2.cpp

I would like to be able to compile these files together and execute my macro on the command line, but so far I have been unsuccessful. I’ve considered just compiling all of this together in a shared library, as I did for TParticle.so, but it seems wrong to me, as this is just a macro with several helper functions. I’ve also tried looking at sample makefiles to use gcc to link the root libraries, my TParticle library and these macro .h and .cpp files together , but all of the makefiles are very tedious and general, and I’m just hoping to get something simple which will allow me to go to the command line and type

root [0] .L myprogram.appropriateextension(+)
root [1] doit(100,100)

Thanks in advance for considering this post. I am mainly trying to learn the appropriate way to do this programming, such that I can build larger and more successful programs in the proper way.

  • Brendan

I would recommend against using the word TParticle as it is also the name of an official ROOT class.

In the first approximation, you can simply #include helper1.cpp and helper2.cpp in doit.cpp and do

.L doit.cpp+

Also note that if you add

#ifdef __MAKECINT__ #pragma link C++ function myherlper_function; #endif
in any of this file, this request will be honored by ACLiC.

You can also simply write a macro loader.C

{ gROOT->ProcessLine(".L helper1.cpp+"); gROOT->ProcessLine(".L helper2.cpp+"); gROOT->ProcessLine(".L doit.cpp+"); }
and then do

.x loader.C

Cheers,
Philippe.

I am facing the same problem, pcanal’s answer helped me solve at least the compiling part, but once I have compiled all the source (cpp) files using .L file.cpp+, how do I link those .so files ? Suppose I have a main macro, macro.cpp and two headers, h1.cpp, h1.h and h2.cpp and h2.h, macro.cpp calls functions from h1 and h2, after compiling them all I get macro_cpp.so, h1_cpp.so and h2_cpp.so… how to proceed ?

Hi,

See also ACLiC complains about almost everything, why doesn't it recognize any ROOT Types like TCanvas etc?

Repeating the same question on four threads (if I counted correctly) doesn’t get you closer to an answer but makes it more confusing for you, us and anybody else with the same question who is trying to find your solution.

Cheers, Axel.

Finally solved it Is there any tutorial on running root entirely with g++?, the questions are different but related.