I want to add a custom class to ROOT, and I’m using the following tutorial by @eguiraud . I am using the rootcling way.
My problem is that, once I have used rootcling to make the dictionaries, I want to compile it with g++ using g++ -o TFeynman_readwrite TFeynman_readwrite.cpp $(root-config --libs --cflags) TFeynman.cxx TFeynman_dict.cpp . When I do this I get the following error:
/usr/bin/ld: /home/advait/rootbuild/lib/libGpad.so: undefined reference to symbol '_ZN6TLatexC1EddPKc'
/usr/bin/ld: /home/advait/rootbuild/lib/libGraf.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
After doing some digging online, apparently I have to add -lpthread to the command line. Is this correct? And if yes, how do I do this? Here are my files:
UPDATE: When I use the cmake method I get this error:
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o: in function `__static_initialization_and_destruction_0(int, int)':
TFeynman.cxx:(.text+0x1958): undefined reference to `ROOT::GenerateInitInstance(TFeynmanEntry const*)'
/usr/bin/ld: TFeynman.cxx:(.text+0x197c): undefined reference to `ROOT::GenerateInitInstance(TFeynman const*)'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o: in function `TFeynman::IsA() const':
TFeynman.cxx:(.text._ZNK8TFeynman3IsAEv[_ZNK8TFeynman3IsAEv]+0x11): undefined reference to `TFeynman::Class()'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o: in function `TFeynman::ShowMembers(TMemberInspector&) const':
TFeynman.cxx:(.text._ZNK8TFeynman11ShowMembersER16TMemberInspector[_ZNK8TFeynman11ShowMembersER16TMemberInspector]+0x15): undefined reference to `TFeynman::Class()'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o:(.data.rel.ro._ZTV8TFeynman[_ZTV8TFeynman]+0x90): undefined reference to `TFeynman::Streamer(TBuffer&)'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o:(.data.rel.ro._ZTV8TFeynman[_ZTV8TFeynman]+0x288): undefined reference to `non-virtual thunk to TFeynman::Streamer(TBuffer&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/TFeynman.dir/build.make:110: TFeynman] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/TFeynman.dir/all] Error 2
You are missing a -lGraf on the compiler command line, i.e. that shared object provides the TLatex::TLatex() constructor. It seems that it is not included by default in the list provided by root-config --libs; adding that option manually should fix your issue.
/usr/bin/ld: /tmp/ccm9ljFH.o: in function `__static_initialization_and_destruction_0(int, int)': TFeynman.cxx:(.text+0x1958): undefined reference to `ROOT::GenerateInitInstance(TFeynmanEntry const*)' collect2: error: ld returned 1 exit status
This error means that the source file or library that defines ROOT::GenerateInitInstance(TFeynmanEntry const*) needs to be present in your compilation command and it needs to come afterTFeynman.cxx, which needs that symbol.
I guess ROOT::GenerateInitInstance(TFeynmanEntry const*) should be defined in TFeynman_dict.cpp, is it there?
Is this not what you proposed above? root-config --cxx --cflags` -o TFeynman_readwrite TFeynman_readwrite.cpp TFeynman.cxx TFeynman_dict.cpp `root-config --libs
That’s not the symbol that’s missing, the linker complains about GenerateInitInstance(TFeynmanEntry const*), not GenerateInitInstance(const TFeynman*).
Is TFeynmanEntry also in your LinkDef? If not maybe try adding it?