Error in CMake with FairRoot

Good morning,

I tried to add root to my Cmake( I have attached my CMakeLists.txt). I am new to CMake and root as well. I want to include FairRunAna in my main.cpp file, but I get this error when building my cmake. Please how I can solve this. Thank you very much in advance

harriet@harriet-ROG-Zephyrus-G15-GA503RM-GA503RM:~/kalman filter/OpenKF/build$ cmake ../
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:47 (target_link_libraries):
  Cannot specify link libraries for target
  "/home/harriet/root/root-6.28.04/root-install/lib/libCore.so" which is not
  built by this project.


-- Configuring incomplete, errors occurred!
See also "/home/harriet/kalman filter/OpenKF/build/CMakeFiles/CMakeOutput.log".

main.cpp (6.5 KB)
CMakeLists.txt (1.9 KB)

_ROOT Version:root-6.28.04
_Platform: Ubuntu 22.04.3 LTS
_Compiler: cmake

Dear @Harriet_Kumi ,

Thanks for reaching out on the forum! Maybe @bellenot can help you.

Cheers,
Vincenzo

Everything is wrong in your CMakeLists.txt, I cannot even understand what you’re trying to do. Where did you get it from? Can you describe your project in details? I.e. what is the are your source and header files, in which subdirectories they are, and so on?

Hi ,

please I am performing the kalman filter for charge particle moving in magnetic and electric field. I wanted to adapt the OpenKf from the github. GitHub - Al-khwarizmi-780/OpenKF: This is an open source Kalman filter C++ library based on Eigen3 library for matrix operations. The library has generic template based classes for most of Kalman filter variants including: (1) Kalman Filter, (2) Extended Kalman Filter, (3) Unscented Kalman Filter, and (4) Square-root UKF... The only problem I was facing was taking the data from the ATTPC and adapting it in this case. I could add the ATTPCROOTv2 to the CmakeLists and the Root also to make it work.

Sorry, I still don’t understand. You want to create your own application using OpenKf and ROOT? Then you should create your own CMakeLists.txt including both packages. Or did I miss something?

this is the already existing CMakeLists. Then I want to add Root and ATTPCROOT, FAIRROOT packages to it but it is not working.

cmake_minimum_required(VERSION 3.4)

# ============================================================================================
# VCPKG Toolchain
# ============================================================================================
if(WIN32)
    # use vcpkg as packages manager in windows platform
    # environment variable needs to be added for the path to vcpkg installation "VCPKG_ROOT"
    set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif(WIN32)

# ============================================================================================
# ============================================================================================
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/build/package)
set(CMAKE_CXX_STANDARD 11)

project(OpenKF)

set(INCLUDE_FOLDER "include")
set(LIBRARY_INSTALL_DIR "lib")
set(INCLUDE_INSTALL_DIR "${INCLUDE_FOLDER}/${PROJECT_NAME}")
set(CONFIG_INSTALL_DIR  "${LIBRARY_INSTALL_DIR}/cmake/${PROJECT_NAME}")
set(namespace "%{PROJECT_NAME}::")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")

enable_language(C CXX)

find_package(Eigen3 3.3 REQUIRED NO_MODULE)

add_subdirectory(kalman_filter)
add_subdirectory(examples)

Because this is not the way to proceed. The CMakeLists.txt you pasted is the one to build OpenKF. You cannot simply add ROOT, ATTPCROOT, and FAIRROOT packages to it. As I said, you have to write your own CMakeLists.txt with something like this:

cmake_minimum_required(VERSION 3.16)

project("yourProject")

# Find the ROOT package
find_package(ROOT REQUIRED)
find_package(OpenKF REQUIRED) # or whatever the name is
find_package(ATTPCROOT REQUIRED) # or whatever the name is
find_package(FAIRROOT REQUIRED) # or whatever the name is

# Include directories
include_directories(${ROOT_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/inc)

# Specify C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS ${ROOT_CXX_FLAGS})

# Add executable
add_executable(yourProject yourSource.cxx)
target_link_libraries(yourProject ${ROOT_LIBRARIES} ATTPCReco FairTools Base)

If those packages can be used like this in a CMakeLists.txt. I know ROOT will work, but I don’t know for the other ones…

okay thank you very much I will do that.

1 Like