# Error in CMake with FairRoot

**URL:** <https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205>\
**Category:** Newbie\
**Created:** [November 22, 2023, 9:25am UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205 "2023-11-22T09:25:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harriet\_Kumi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/harriet_kumi/32/31605_2.png) [@Harriet\_Kumi](https://root-forum.cern.ch/u/Harriet_Kumi)\
**Post date:** [November 22, 2023, 9:25am UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/1 "2023-11-22T09:25:00Z")

</div>

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

```auto
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](https://root-forum.cern.ch/uploads/short-url/mhRw9R2EDOmFYFpEYdD96V4rIBE.cpp) (6.5 KB)  
[CMakeLists.txt](https://root-forum.cern.ch/uploads/short-url/7g5ykfFoM71CAjoBrSNVdGecdxz.txt) (1.9 KB)

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

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [December 12, 2023, 9:42am UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/2 "2023-12-12T09:42:08Z")

</div>

Dear @Harriet_Kumi ,

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

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 12, 2023, 9:55am UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/3 "2023-12-12T09:55:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Harriet\_Kumi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/harriet_kumi/32/31605_2.png) [@Harriet\_Kumi](https://root-forum.cern.ch/u/Harriet_Kumi)\
**Post date:** [December 14, 2023, 3:09pm UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/4 "2023-12-14T15:09:26Z")

</div>

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..](https://github.com/Al-khwarizmi-780/OpenKF). 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.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 14, 2023, 3:17pm UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/5 "2023-12-14T15:17:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Harriet\_Kumi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/harriet_kumi/32/31605_2.png) [@Harriet\_Kumi](https://root-forum.cern.ch/u/Harriet_Kumi)\
**Post date:** [December 14, 2023, 3:26pm UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/6 "2023-12-14T15:26:05Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 14, 2023, 3:44pm UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/7 "2023-12-14T15:44:07Z")

</div>

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:

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

---

<div class="post-metadata">

**Author:** ![Harriet\_Kumi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/harriet_kumi/32/31605_2.png) [@Harriet\_Kumi](https://root-forum.cern.ch/u/Harriet_Kumi)\
**Post date:** [December 14, 2023, 4:02pm UTC](https://root-forum.cern.ch/t/error-in-cmake-with-fairroot/57205/8 "2023-12-14T16:02:59Z")

</div>

okay thank you very much I will do that.
