ROOT Version: 6.20.04 Platform: CentOS 7 Compiler: gcc version 9.1.1 20190605 (Red Hat 9.1.1-2) ___
Hi.
I just recently ported my code from macOS to CentOS and I am having trouble running it. I keep on getting “undefined reference to” errors. I checked if the Roofit libraries exist in my ROOT build directory and they are there. Here is the error I get:
opt/rh/devtoolset-9/root/usr/bin/ld: libHistFactorySimultaneous.a(HistFactorySimultaneous.cxx.o): in function `RooStats::HistFactory::HistFactorySimultaneous::createNLL(RooAbsData&, RooLinkedList const&)':
/home/xola/test/UJ_LimitSetting/src/HistFactorySimultaneous.cxx:127: undefined reference to `RooStats::HistFactory::RooBarlowBeestonLL::RooBarlowBeestonLL(char const*, char const*, RooAbsReal&)'
/opt/rh/devtoolset-9/root/usr/bin/ld: /home/xola/test/UJ_LimitSetting/src/HistFactorySimultaneous.cxx:130: undefined reference to `RooStats::HistFactory::RooBarlowBeestonLL::initializeBarlowCache()'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/StandardHypoTestInv.dir/build.make:148: StandardHypoTestInv] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:881: CMakeFiles/StandardHypoTestInv.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:888: CMakeFiles/StandardHypoTestInv.dir/rule] Error 2
gmake: *** [Makefile:456: StandardHypoTestInv] Error 2```
You will notice in the CMakeLists.txt file that I did link to RooFitCore. I omitted histfactory and imported the source and header files from histfactory so that they run on my local directory. This works on Mac OS but for some reason the exact same project give me liking errors in CentOS
Oh ok here’s the CMakeCache.txt file that shows that the project links to libRooFitCore. Thing is I use cmake so instead of using a linking line I just call cmake in the directory that contains the CmakeList.txt file. CMakeCache.txt (28.8 KB)
Sorry about that. Got the project to build verbose. So I see that is does link to libRoofitCore.so and does not link to libHistFactory.so. I did this on purpose so that the histfactory source code and header files build on my local directory. But then I get linking errors for RooStats::HistFactory::RooBarlowBeestonLL::RooBarlowBeestonLL() while I have the .cxx and .h files in my local directory. This happens when building on CentOS 7 but not on macOS error.txt (66.4 KB)
I see … You are trying to replace HistFactory by your own version … and from the verbose, I see that your libraries are static libraries. In this case you need to make sure that the .a that contains the missing library is listed after the one that uses it. You should also double check that the symbol did make it into the library (see nm -A *.a | grep initializeBarlowCache)
So I did the command in the cmake-build-debug directory and got this output:
libHistFactorySimultaneous.a:HistFactorySimultaneous.cxx.o: U _ZN8RooStats11HistFactory18RooBarlowBeestonLL21initializeBarlowCacheEv
libRooBarlowBeestonLL.a:RooBarlowBeestonLL.cxx.o:0000000000000636 T _ZN8RooStats11HistFactory18RooBarlowBeestonLL21initializeBarlowCacheEv
It looks like the symbol is referenced but not defined in HistFactorySimultaneous
I have the impression that this cannot work. I see, for example, that your CMakeLists.txt has classes from the ROOT distribution in its LinkDefs:
"#pragma link C++ namespace RooStats;\n"
"#pragma link C++ namespace RooStats::HistFactory;\n"
# "#ifdef USE_FOR_AUTLOADING \n"
"#pragma link C++ class RooStats::HistFactory;\n"
"#pragma link C++ class RooStats; "
# "#endif\n"
"#pragma link C++ nestedclasses;\n"
"#pragma link C++ nestedtypedefs;\n"
"#pragma link C++ class std::map<std::string,RooAbsPdf*>+ ;\n"
"#pragma link C++ class RooStats::HistFactory::RooBarlowBeestonLL+ ;\n"
Also the tons of add_library_link_def(ROOTClass) look wrong. They try to do work that has already been done inside ROOT, and that inevitably leads to clashes. There are already dictionaries for all these inside ROOT, so
add_executable(StandardHypoTestInv StandardHypoTestInv.cxx HistFactoryException.cxx)
target_link_libraries(StandardHypoTestInv PUBLIC ROOT::RooStats ROOT::HistFactory)
Hi @pcanal@StephanH found that the order in which the classes were listed in target_link_libraries did cause the problem. Class should be listed before the one it depends on. I dont understand why this is a problem in linux and not Mac