Undefined reference error

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```

What does you link line look like? (i.e. is linking against libRooFitCore ?)

Hi

So I use cmake to generate my executable

CMakeLists.txt (6.7 KB)

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

Actually, I don’t :slight_smile: … I see that it is listed in the find_package but (unless I am missing something) I don’t see it anywhere else.

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)

This is not yet convincing (in large part because the link error says it isn’t used on the link line).

Try to build in verbose mode to see what actual command line is used to be link.

Hi

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)

Hi @pcanal.

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

Try adding

libRooBarlowBeestonLL.a

at the end of the failing command line (I.e. copy/paste the line and add by hand)

Hi @pcanal sorry for the late response. Can you please explain which command line you are referring to?

Hi @pcanal.

So I first did :

 /opt/clion-2020.1/bin/cmake/linux/bin/cmake --build /home/xola/UJ_LimitSetting/src/cmake-build-debug --target RooBarlowBeestonLL -- -j 8

so that I can generate a libRooBarlowBeestonLL.a file.I then did:

/opt/clion-2020.1/bin/cmake/linux/bin/cmake --build /home/xola/UJ_LimitSetting/src/cmake-build-debug --target HistFactorySimultaneous -- -j 8 libRooBarlowBeestonLL.a

and got the following output:

gmake: Nothing to be done for 'libRooBarlowBeestonLL.a'.
/opt/clion-2020.1/bin/cmake/linux/bin/cmake -S/home/xola/UJ_LimitSetting/src -B/home/xola/UJ_LimitSetting/src/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/opt/rh/devtoolset-9/root/usr/bin/gmake -f CMakeFiles/Makefile2 HistFactorySimultaneous
gmake[1]: Entering directory '/home/xola/UJ_LimitSetting/src/cmake-build-debug'
/opt/clion-2020.1/bin/cmake/linux/bin/cmake -S/home/xola/UJ_LimitSetting/src -B/home/xola/UJ_LimitSetting/src/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/opt/clion-2020.1/bin/cmake/linux/bin/cmake -E cmake_progress_start /home/xola/UJ_LimitSetting/src/cmake-build-debug/CMakeFiles 1
/opt/rh/devtoolset-9/root/usr/bin/gmake -f CMakeFiles/Makefile2 CMakeFiles/HistFactorySimultaneous.dir/all
gmake[2]: Entering directory '/home/xola/UJ_LimitSetting/src/cmake-build-debug'
/opt/rh/devtoolset-9/root/usr/bin/gmake -f CMakeFiles/HistFactorySimultaneous.dir/build.make CMakeFiles/HistFactorySimultaneous.dir/depend
gmake[3]: Entering directory '/home/xola/UJ_LimitSetting/src/cmake-build-debug'
[  0%] Generating G__HistFactorySimultaneous.cxx, libHistFactorySimultaneous_rdict.pcm, libHistFactorySimultaneous.rootmap
/opt/clion-2020.1/bin/cmake/linux/bin/cmake -E env LD_LIBRARY_PATH=/home/xola/root/root-6.18.04-installdir/lib:/home/xola/root/root-6.18.04-installdir/lib:/opt/rh/devtoolset-9/root/usr/lib64:/opt/rh/devtoolset-9/root/usr/lib:/opt/rh/devtoolset-9/root/usr/lib64/dyninst:/opt/rh/devtoolset-9/root/usr/lib/dyninst:/opt/rh/devtoolset-9/root/usr/lib64:/opt/rh/devtoolset-9/root/usr/lib:/opt/geant4/geant4.10.06.p01-install/lib64 /home/xola/root/root-6.18.04-installdir/bin/rootcling -v2 -f G__HistFactorySimultaneous.cxx -s /home/xola/UJ_LimitSetting/src/cmake-build-debug/libHistFactorySimultaneous.so -rml libHistFactorySimultaneous.so -rmf /home/xola/UJ_LimitSetting/src/cmake-build-debug/libHistFactorySimultaneous.rootmap -I/home/xola/UJ_LimitSetting/src/inc -I/home/xola/root/root-6.18.04-installdir/include -I/home/xola/UJ_LimitSetting/src HistFactorySimultaneous.h /home/xola/UJ_LimitSetting/src/cmake-build-debug/RootDict/HistFactorySimultaneousDict_LinkDef.h
cd /home/xola/UJ_LimitSetting/src/cmake-build-debug && /opt/clion-2020.1/bin/cmake/linux/bin/cmake -E cmake_depends "Unix Makefiles" /home/xola/UJ_LimitSetting/src /home/xola/UJ_LimitSetting/src /home/xola/UJ_LimitSetting/src/cmake-build-debug /home/xola/UJ_LimitSetting/src/cmake-build-debug /home/xola/UJ_LimitSetting/src/cmake-build-debug/CMakeFiles/HistFactorySimultaneous.dir/DependInfo.cmake --color=
Scanning dependencies of target HistFactorySimultaneous
gmake[3]: Leaving directory '/home/xola/UJ_LimitSetting/src/cmake-build-debug'
/opt/rh/devtoolset-9/root/usr/bin/gmake -f CMakeFiles/HistFactorySimultaneous.dir/build.make CMakeFiles/HistFactorySimultaneous.dir/build
gmake[3]: Entering directory '/home/xola/UJ_LimitSetting/src/cmake-build-debug'
[  0%] Building CXX object CMakeFiles/HistFactorySimultaneous.dir/G__HistFactorySimultaneous.cxx.o
/usr/local/bin/c++   -I/home/xola/UJ_LimitSetting/src/inc -isystem /home/xola/root/root-6.18.04-installdir/include  -std=c++11 -pipe -fsigned-char -pthread -g   -std=gnu++11 -o CMakeFiles/HistFactorySimultaneous.dir/G__HistFactorySimultaneous.cxx.o -c /home/xola/UJ_LimitSetting/src/cmake-build-debug/G__HistFactorySimultaneous.cxx
[  0%] Building CXX object CMakeFiles/HistFactorySimultaneous.dir/HistFactorySimultaneous.cxx.o
/usr/local/bin/c++   -I/home/xola/UJ_LimitSetting/src/inc -isystem /home/xola/root/root-6.18.04-installdir/include  -std=c++11 -pipe -fsigned-char -pthread -g   -std=gnu++11 -o CMakeFiles/HistFactorySimultaneous.dir/HistFactorySimultaneous.cxx.o -c /home/xola/UJ_LimitSetting/src/HistFactorySimultaneous.cxx
[100%] Linking CXX static library libHistFactorySimultaneous.a
/opt/clion-2020.1/bin/cmake/linux/bin/cmake -P CMakeFiles/HistFactorySimultaneous.dir/cmake_clean_target.cmake
/opt/clion-2020.1/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/HistFactorySimultaneous.dir/link.txt --verbose=1
/opt/rh/devtoolset-9/root/usr/bin/ar qc libHistFactorySimultaneous.a  CMakeFiles/HistFactorySimultaneous.dir/G__HistFactorySimultaneous.cxx.o CMakeFiles/HistFactorySimultaneous.dir/HistFactorySimultaneous.cxx.o
/opt/rh/devtoolset-9/root/usr/bin/ranlib libHistFactorySimultaneous.a
gmake[3]: Leaving directory '/home/xola/UJ_LimitSetting/src/cmake-build-debug'
[100%] Built target HistFactorySimultaneous
gmake[2]: Leaving directory '/home/xola/UJ_LimitSetting/src/cmake-build-debug'
/opt/clion-2020.1/bin/cmake/linux/bin/cmake -E cmake_progress_start /home/xola/UJ_LimitSetting/src/cmake-build-debug/CMakeFiles 0
g

It seems as though HistFactorySimultaneous is not using RooBarlowBeestoLL for some reason.

Hello @Xola,

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)

is all you should do.

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

Ok, good to know.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.