Crisps
April 15, 2023, 12:12pm
1
Dear experts
I got an error when I tried to build my program with ROOT, the error is:
Undefined symbols for architecture arm64
"TSpectrum2::SearchHighRes(double**, double**, int, int, double, double, bool, int, bool, int)", referenced from:
CRTTracking::FindHoughPeak(TH2D*, int, int, double, double, double, double) const in CRTTracking.cxx.o
"TSpectrum2::TSpectrum2(int, double)", referenced from:
CRTTracking::FindHoughPeak(TH2D*, int, int, double, double, double, double) const in CRTTracking.cxx.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I checked that I added TSpectrum2.h in my header files, and here is my CMakeLists.txt :
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(CRTTracking)
set(CMAKE_CXX_STANDARD 14)
find_package(ROOT REQUIRED)
add_library(Tracking ${CMAKE_CURRENT_SOURCE_DIR}/src/CRTTracking.cxx)
target_include_directories(Tracking PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
${ROOT_INCLUDE_DIRS})
target_link_libraries(Tracking ${ROOT_LIBRARIES})
add_executable(CRTTracking ${CMAKE_CURRENT_SOURCE_DIR}/src/CRTTracking.cxx)
target_link_libraries(CRTTracking PUBLIC Tracking)
install(TARGETS CRTTracking
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin)
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
Try: target_link_libraries(Tracking ${ROOT_LIBRARIES} ROOT::Spectrum)
Crisps
April 15, 2023, 1:54pm
3
Thank you! This works, but how can I know which library should I link? I thought ${ROOT_LIBRARIES} simply included all libraries in ROOT…
I guess “${ROOT_LIBRARIES}
” correspond to: root-config --libs
Crisps
April 15, 2023, 2:48pm
5
This gives what libraries ROOT contains, but how can I know which one I should link? If ${ROOT_LIBRARIES} doesn’t include all of them, which one it includes? Sorry I’m really new on ROOT and CMake, maybe these are basic knowledges
ls -al ${ROOTSYS}/cmake/ROOTConfig-targets*.cmake
In ROOT 6.18 and earlier, for each “${ROOTSYS}/lib/lib*.so” library, there existed a corresponding “${ROOTSYS}/lib/lib*.rootmap” text file.
This allowed e.g. to easily find which library was needed for a class (when linking errors appeared).
In ROOT 6.19 and newer, there exist only “${ROOTSYS}/lib/*.pcm” binary files.
What is the command which dumps the contents of these files in a human readable (ASCII) form?
I guess I would like to get (ASCII) text output which kind of “resembles” what was…
Crisps
April 15, 2023, 3:24pm
7
Thank you, now I know which library I should link when compiling. And for the second question (what does $ROOT_LIBRARIES contains), I had a look at ROOTConfig.cmake , I found these lines:
set(ROOT_LIBRARIES)
if(MSVC)
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
endif()
foreach(_cpt Core Imt RIO Net Hist Graf Graf3d Gpad ROOTDataFrame Tree TreePlayer Rint Postscript Matrix Physics MathCore Thread MultiProc ROOTVecOps ${ROOT_FIND_COMPONENTS})
find_library(ROOT_${_cpt}_LIBRARY ${_cpt} HINTS ${ROOT_LIBRARY_DIR})
if(ROOT_${_cpt}_LIBRARY)
mark_as_advanced(ROOT_${_cpt}_LIBRARY)
list(APPEND ROOT_LIBRARIES ${ROOT_${_cpt}_LIBRARY})
list(REMOVE_ITEM ROOT_FIND_COMPONENTS ${_cpt})
endif()
endforeach()
does the foreach line give exactly what libraries ${ROOT_LIBRARIES} contains?
Actually, maybe instead of manually modifying the “target_link_libraries
”, you could try a better (?) approach:
find_package(ROOT REQUIRED COMPONENTS Spectrum)
Crisps
April 17, 2023, 1:58am
9
Yes you are right, I think this should follow what CMakeLists original designed for user’s usage, thank you!