Compile multiple files

Suppose I have two C++ files, foo.cpp and bar.cpp, which are dependent on each other’s function definitions. Is it possible to compile both files in ROOT? I get an error if I just try

.L foo.cpp+.


you could #include one file in the other, or create a thord file #including the two. Yes, also .cpp files can be #included :slight_smile:

Cheers, Axel.

Thanks for the response. Bear with me for a moment. I just tried the following:


#include bar.cpp
#include bar.h
#include <stdio.h>
int main(void)
  return 0;


char* word(void)
  return "hello\n";

It compiles fine with g++.
When I run .L main.cpp+ I am told that a shared library has been made. Then when I run


I get the following error:

root [1] main()
Error in <TApplication::TApplication>: only one instance of TApplication allowed
Note: File "iostream" already loaded
Note: File "_string" already loaded
Note: File "RtypesCint.h" already loaded
Note: File "DllImport.h" already loaded
root [0] 
 *** Break *** segmentation violation
Attaching to program: /proc/1032/exe, process 1032
[Thread debugging using libthread_db enabled]
0x0000003e14299d75 in waitpid () from /lib64/
#1  0x0000003e1423c331 in do_system () from /lib64/
#2  0x00002b661caee51c in TUnixSystem::StackTrace() () from /root/software/root/lib/
#3  0x00002b661caeba4a in TUnixSystem::DispatchSignals(ESignals) () from /root/software/root/lib/
#4  <signal handler called>
#5  0x00002b661ca1e6e9 in TBrowser::Add(TObject*, char const*, int) () from /root/software/root/lib/
#6  0x00002b661cab6676 in TAutoInspector::Inspect(TClass*, char const*, char const*, void const*) () from /root/software/root/lib/
#7  0x00002b661ccbcb91 in TObjString::ShowMembers(TMemberInspector&, char*) () from /root/software/root/lib/
#8  0x00002b661caab43a in TClass::AutoBrowse(TObject*, TBrowser*) () from /root/software/root/lib/
#9  0x00002b661e2a847d in TRint::Run(bool) () from /root/software/root/lib/
#10 0x000000000040100d in main ()
A debugging session is active.

        Inferior 1 [process 1032] will be detached.

Quit anyway? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/1032/exe, process 1032
Root > 

Is calling main() the wrong way to run the compiled program?


Just modify the name of your function main() to foo() and it should work.
The mean idea of a compiled macro is to have optimized functions and classes, not a main() function like C++.