"undefined reference to" errors

Hello,

I’m trying to use some ROOT classes but to no sucess. I’m using the conda-forge package.

For whatever reason some ROOT classes, such as TCanvas and TFile, will work if and only if I include the Garfield++ toolkit when building the executables. Other classes such as TTree just won’t work no matter what I do.

With the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(test)
find_package(Garfield REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test Garfield::Garfield)
}

I can execute the following code without any problems:

#include <cstdlib>
#include <TROOT.h>
#include <TFile.h>

int main(int argc, char* argv[]){
  TFile f("test.root", "new");
  return 0;
}

But the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(test)
add_executable(test test.cpp)
}

Triggers the following error when building the executable:

I’ve already tried a pre-compiled binary, also to no sucess. I’m quite new to the ROOT framework and CMake and just can’t seem to find the problem. I’ll be glad to provide more information if needed.

ROOT Version: 6.32.2
Platform: Ubuntu 24.04
Compiler: GNU 12.4.0


Hi Gabriel,

Thanks for the post and welcome to the ROOT Community!
Sorry to read ROOT does not work out of the box in your setup.

The fact you can build the simple program and run it ok is reassuring: it means ROOT works.

About CMake, are you sure you are using there the same ROOT you used for the simple executable? There could be something wrong with your setup: it looks some debugging is needed on your side.

For anything Garfield related, I am adding @hschindl

Cheers,
D

1 Like

Hello,

I was able to solve the problem after installing the pre-compiled binary again. I read here that CMake was supposed to find the ROOT package from Conda automatically, but for whatever reason that wasn’t happening.

After deactivating the Conda environment and installing the binary again, I was finally able to link the ROOT classes to my project using CMake.

I don’t know why the binary distribution worked the 2nd time. I might’ve forgotten to deactivate the Conda env the 1st time, or I didn’t properly link the package using CMake. Either way, I appreciate your attention.