Hi,
When I use CMake to compile a C++ program that using ROOT library.I’m in a trouble.
The directory structure of this program like this :
├── build
├── CMakeLists.txt
├── include
│ └── Recoil_Energy_Spectrum.hh
└── src
├── CMakeLists.txt
└── Recoil_Energy_Spectrum.cc
The contents of CMakeLists.txt in PROJECT_SOURCE_DIR:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(Recoil_Energy_Spectrum)
set(CMAKE_CXX_FLAGS "-std=c++11")
find_package(ROOT REQUIRED)
include_directories(${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS})
link_directories($ENV{ROOTSYS}/lib)
add_subdirectory(src)
And the contents of CMakeLists.txt in /src :
add_executable(Recoil_Energy_Spectrum Recoil_Energy_Spectrum.cc)
target_link_directories(Recoil_Energy_Spectrum PUBLIC ${ROOT_LIBRARIES})
When I compile this program,the compiler said it could’t link to ROOT libraries.How to solve this problem?
Thanks.
ROOT Version: 6.20/02
Platform: Linux
Compiler: GNU 8.3.0