Error compiling with Root Libraries (root-config)


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hello everyone.
I’ve just installed ROOT in my new laptop and I am having trouble trying to run my first problem. I imported this Makefile from my previous laptop because it was working well:

SRC = $(wildcard src/*.cpp)

INC = $(wildcard src/*.h)

MAIN = $(wildcard main/*.cpp)

CXX = g++ $(shell root-config --cflags) -I src

ROOTLIB = $(shell root-config --libs)

####################################

SRC_OBJ = $(patsubst %.cpp, bin/%.o, $(notdir $(SRC)))

MAIN_OBJ = $(patsubst %.cpp, bin/%.o, $(notdir $(MAIN)))

bin/%.exe: bin/%.o $(SRC_OBJ)

@echo "compiling and liking file [ $< ] to $@ "

$(CXX) $< -o $@ $(SRC_OBJ) $(ROOTLIB)

bin/%.o: src/%.cpp

@echo "compiling file [ $< ] to $@ "

$(CXX) -c $< -o $@

bin/%.o: main/%.cpp

@echo "compiling file [ $< ] to $@ "

$(CXX) -c $< -o $@

####################################

FTILDE = $(wildcard src/~) $(wildcard main/~)

FBIN = $(wildcard bin/*.o)

clean:

@echo "cleaning..."

@rm -fv $(FBIN)

dump:

@echo "dump list of src files..."

@echo $(SRC)

@echo $(INC)

@echo $(MAIN)

@echo $(FTILDE)

@echo $(FBIN)

@echo $(CXX)

@echo $(SRC_OBJ)

However, while compiling a file containg TApplication, TGraph, etc, this error occured:

make: root-config: No such file or directory
compiling file [ main/fitPanel.cpp ] to bin/fitPanel.o
g++  -I src -c main/fitPanel.cpp -o bin/fitPanel.o
main/fitPanel.cpp:8:10: fatal error: TApplication.h: No such file or directory
    8 | #include "TApplication.h"
      |          ^~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:29: bin/fitPanel.o] Error 1

and I don’t understand why, since it was working in my previous laptop, with the same file…
I believe the error is due to the fact that it is not finding root-config, because the path for the ROOT Libraries are ok.
I would appreciate your help.

Here is the file that I am trying to compile, if needed:

/*
Fitar dados a gaussianas. O programa abre o fitPanel para ser mais rápido e prático. Incertezas no eixos dos yy
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include "TApplication.h"
#include "TF1.h"
#include "TCanvas.h"
#include "TGraphErrors.h"
#include "TAxis.h"


void FitData()
{
    // Create a TApplication for the ROOT graphics
    TApplication app("app", nullptr, nullptr);

    // Read data from file
    std::ifstream file("/home/diogo/analysis/main/data/something.txt");
    if (!file.is_open())
    {
        std::cout << "Failed to open data file." << std::endl;
        return;
    }

    // Arrays to store data
    std::vector<double> xValues;
    std::vector<double> NA_Values;
    std::vector<double> v_NA_Errors;
    std::vector<double> NB_Values;
    std::vector<double> v_NB_Errors;
    std::vector<double> NC_Values;
    std::vector<double> v_NC_Errors;

    std::string line;
    while (std::getline(file, line))
    {
        std::istringstream iss(line);
        double x, NA, NA_err, NB, NB_err, NC, NC_err;
        if (iss >> x >> NA >> NA_err >> NB >> NB_err >> NC >> NC_err)
        {
            xValues.push_back(x);
            NA_Values.push_back(NA);
            v_NA_Errors.push_back(NA_err);
            NB_Values.push_back(NB);
            v_NB_Errors.push_back(NB_err);
            NC_Values.push_back(NC);
            v_NC_Errors.push_back(NC_err);
        }
    }

    file.close();

    // Create a TGraphErrors from the data
    int numPoints = xValues.size();
    TGraphErrors *graph = new TGraphErrors(numPoints, &xValues[0], &NC_Values[0], 0, &v_NC_Errors[0]);

    graph->SetTitle("Blindagem");
    graph->GetXaxis()->SetTitle("#theta (degrees)");
    graph->GetYaxis()->SetTitle("NC(#theta) (cts)");

    graph->GetXaxis()->CenterTitle(true);
    graph->GetYaxis()->CenterTitle(true);

    // Create a canvas to display the graph
    TCanvas *canvas = new TCanvas("canvas", "Data Fitting", 800, 600);
    graph->Draw("AP"); // "AP" option to display both markers and error bars

    // Launch the ROOT Fit Panel
    canvas->Update(); // Update the canvas to display the graph
    canvas->cd();
    graph->FitPanel();

    // Wait for the Fit Panel to be closed
    app.Run();

}

int main()
{
    FitData();
    return 0;
}

Thank you,
Diogo Franco

Ups I forgot to provide some information:
My root version is the latest one since I have just installed it.
I am working on wsl ubuntu, with c++.
The compiler is in the Makefile I sent.
Thank you!

The main error message is:

i.e. root-config is not in your path. Do something like:

. /path/to/where/root/is/installed/bin/thisroot.sh

(.csh is your using a c-shell)

Hi! Thank you for helping me. The root-config error disappeared. However, now it is giving a new one when I compile the file:

compiling file [ main/fitPanel.cpp ] to bin/fitPanel.o
g++ -pthread -std=c++17 -m64 -I/home/diogo/root-6.28.06-install/include -I src -c main/fitPanel.cpp -o bin/fitPanel.o
In file included from /home/diogo/root-6.28.06-install/include/Rtypes.h:23,
                 from /home/diogo/root-6.28.06-install/include/TObject.h:17,
                 from /home/diogo/root-6.28.06-install/include/TApplication.h:28,
                 from main/fitPanel.cpp:8:
/home/diogo/root-6.28.06-install/include/RtypesCore.h:23:10: fatal error: RConfig.hxx: No such file or directory
   23 | #include <RConfig.hxx>
      |          ^~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:29: bin/fitPanel.o] Error 1

It looks like it is not finding the library for some reason… (I am not even calling the RConfig though, why is it here?)

I exit ubuntu and when I opened it again I had to write the command again… Is there any way to put it automatic or something like that?
Thank you for your help!
Diogo Franco.

You can put the command in the .bashrc (or .tcshrc) script (in your home directory).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

This is very odd, this line of code does not exist the repository (that I can tell). Instead at that line
we have:

#include <ROOT/RConfig.hxx>