Home > front end >  Linker error while building a ROOT class "RooUnfold" in Mac using cmake
Linker error while building a ROOT class "RooUnfold" in Mac using cmake

Time:06-22

What I want to do
I want to build a ROOT class "RooUnfold" in Mac.

Question
How can I solve linker errors (ld: library not found for -lgcov clang: error: linker command failed with exit code 1 (use -v to see invocation)) which occurs when I tried to build RooUnfold using cmake?

What I did
(1) I installed ROOT on my Mac. It successfully works.
(2) I downloaded and unzipped "RooUnfold-master.zip" from a web cite(https://gitlab.cern.ch/RooUnfold/RooUnfold).
(3) I tried to build RooUnfold following the instructions on the web cite as following :

cd RooUnfold-master
mkdir build
cd build
cmake ..
make -j4
cd ..
source build/setup.sh

(4) However, it was failed when I tried make -j4 with following output :

$ cd RooUnfold-master 
$ mkdir build
$ cd build 
$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:10 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


Setup using plain ROOT
Doxygen build started
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/XXXXXX/RooUnfold-master/build

$ make -j4
[  2%] Generating G__RooUnfold.cxx, libRooUnfold_rdict.pcm, libRooUnfold.rootmap
Scanning dependencies of target RooUnfold
[  9%] Building CXX object CMakeFiles/RooUnfold.dir/src/RooUnfoldBayes.o
[  9%] Building CXX object CMakeFiles/RooUnfold.dir/src/RooUnfold.o
[  9%] Building CXX object CMakeFiles/RooUnfold.dir/src/RooFitUnfold.o
[ 12%] Building CXX object CMakeFiles/RooUnfold.dir/src/RooUnfoldBinByBin.o
In file included from /Users/XXXXXX/RooUnfold-master/src/RooUnfoldBinByBin.cxx:8:
/Users/XXXXXX/RooUnfold-master/src/RooUnfoldBinByBin.h:44:3: warning: 'CheckTObjectHashConsistency' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  ClassDefT (RooUnfoldBinByBinT, 1)  // Bin-by-bin unfolding
  ^
/opt/homebrew/Cellar/root/6.26.04_1/include/root/Rtypes.h:392:4: note: expanded from macro 'ClassDefT'
   _ClassDefOutline_(name,id,virtual,)              \
   ^
/opt/homebrew/Cellar/root/6.26.04_1/include/root/Rtypes.h:300:4: note: expanded from macro '_ClassDefOutline_'
   _ClassDefBase_(name,id, virtual_keyword, overrd)       \
   ^

(a lot of "override" errors)

97 warnings generated.
[ 63%] Linking CXX shared library libRooUnfold.dylib
[ 63%] Built target RooUnfold
[ 73%] Building CXX object CMakeFiles/RooUnfoldTest3D.dir/test/src/RooUnfoldTest3D.o
[ 73%] Building CXX object test/CMakeFiles/RooUnfoldTests.dir/src/generate_test.o
[ 73%] Building CXX object CMakeFiles/RooUnfoldTest2D.dir/test/src/RooUnfoldTest2D.o
[ 73%] Building CXX object CMakeFiles/RooUnfoldTest.dir/test/src/RooUnfoldTest.o
[ 75%] Building CXX object test/CMakeFiles/RooUnfoldTests.dir/src/response_test.o
[ 78%] Linking CXX executable RooUnfoldTest
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [RooUnfoldTest] Error 1
make[1]: *** [CMakeFiles/RooUnfoldTest.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 80%] Building CXX object test/CMakeFiles/RooUnfoldTests.dir/src/bayes_test.o
[ 82%] Linking CXX executable RooUnfoldTest2D
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [RooUnfoldTest2D] Error 1
make[1]: *** [CMakeFiles/RooUnfoldTest2D.dir/all] Error 2
[ 85%] Linking CXX executable RooUnfoldTest3D
[ 87%] Building CXX object test/CMakeFiles/RooUnfoldTests.dir/src/RooUnfold_unit_tests.o
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [RooUnfoldTest3D] Error 1
make[1]: *** [CMakeFiles/RooUnfoldTest3D.dir/all] Error 2
In file included from /Users/XXXXXX/RooUnfold-master/test/src/bayes_test.cxx:13:
/Users/XXXXXX/RooUnfold-master/src/RooUnfoldBayes.h:45:17: warning: 'SetRegParm' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  virtual void  SetRegParm (Double_t parm);
                ^
/Users/XXXXXX/RooUnfold-master/test/src/bayes_test.cxx:31:20: note: in instantiation of template class 'RooUnfoldBayesT<TH1, TH2>' requested here
    RooUnfoldBayes unfold(&response, h_meas, 4);
                   ^
/Users/XXXXXX/RooUnfold-master/src/RooUnfold.h:115:22: note: overridden virtual function is here
  virtual void       SetRegParm (Double_t parm);
                     ^
In file included from /Users/XXXXXX/RooUnfold-master/test/src/bayes_test.cxx:13:
/Users/XXXXXX/RooUnfold-master/src/RooUnfoldBayes.h:46:18: warning: 'GetRegParm' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  virtual double GetRegParm() const;
                 ^
/Users/XXXXXX/RooUnfold-master/src/RooUnfold.h:116:22: note: overridden virtual function is here
  virtual Double_t   GetRegParm() const; // Get Regularisation Parameter
                     ^
In file included from /Users/XXXXXX/RooUnfold-master/test/src/bayes_test.cxx:13:
/Users/XXXXXX/RooUnfold-master/src/RooUnfoldBayes.h:47:16: warning: 'Reset' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  virtual void Reset();
               ^
/Users/XXXXXX/RooUnfold-master/src/RooUnfold.h:74:16: note: overridden virtual function is here
  virtual void Reset ();
               ^
In file included from /Users/XXXXXX/RooUnfold-master/test/src/bayes_test.cxx:13:
/Users/XXXXXX/RooUnfold-master/src/RooUnfoldBayes.h:48:16: warning: 'Print' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  virtual void Print (Option_t* option= "") const;
               ^
/Users/XXXXXX/RooUnfold-master/src/RooUnfold.h:129:8: note: overridden virtual function is here
  void Print(Option_t* opt="") const;
       ^
/Users/XXXXXX/RooUnfold-master/test/src/RooUnfold_unit_tests.cxx:29:62: warning: format specifies type 'unsigned int' but the argument has type 'std::vector<float>::size_type' (aka 'unsigned long') [-Wformat]
    check(n==r.size(), "error in bayes: %d bins is not %u",n,r.size());
                                                       ~~    ^~~~~~~~
                                                       %lu
/Users/XXXXXX/RooUnfold-master/test/src/dbg.h:30:18: note: expanded from macro 'check'
    log_err(M, ##__VA_ARGS__); errno=0; goto error; }
            ~    ^~~~~~~~~~~
/Users/XXXXXX/RooUnfold-master/test/src/dbg.h:20:26: note: expanded from macro 'log_err'
        clean_errno(), ##__VA_ARGS__)
                         ^~~~~~~~~~~
4 warnings generated.
1 warning generated.
[ 90%] Linking CXX static library libRooUnfoldTests.a
[ 90%] Built target RooUnfoldTests
make: *** [all] Error 2

(5) I think the linker errors such as ld: library not found for -lgcov clang: error: linker command failed with exit code 1 (use -v to see invocation) are fatal, but I could not solve them.

Environment

  • Mac OS : Monterey ver. 12.3
  • chip : Apple M1 Pro
  • ROOT : ver. 6.26
$ root --version
ROOT Version: 6.26/04
Built for macosxarm64 on Jun 07 2022, 16:01:16
From tags/v6-26-04@v6-26-04
  • gcc : ver. 13.1.6
$ gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • cmake : ver. 3.22.3
$ cmake --version
cmake version 3.22.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

CodePudding user response:

I think the problem lies in the CMakeLists.txt file. How have to link it. how you would do that is as follows:

...
find_package(ROOT)
...
target_link_libraries(${ROOT_LIBRARIES})
...

CodePudding user response:

I built RooUnfold successfully by using another CMakeFile.txt at https://gitlab.cern.ch/RooUnfold/RooUnfold/-/tree/CMakeLists-fix.
I have not understood the difference completely yet.
However, it may be better to install not from "master", but from "CMakeLists-fix" for Mac users who want to use RooUnfold.

  • Related