Undefined reference to `vtable for ROOT::Minuit2' Error

Hi there,

I am trying to compile the following piece of code in CodeBlocks17:12 and I have root 5.34. I have included all the header files and linked all the libraries using the Settings->Compiler->Search Directories and Linker Settings.

#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnPrint.h"
#include "Minuit2/MnMigrad.h"
#include "Minuit2/FCNBase.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
#include <sstream>

using namespace std;
using namespace ROOT::Minuit2;

class MinFcn : public FCNBase {


  const std::vector< std::vector<double> > & _data;


  MinFcn(const std::vector< std::vector<double> > & data) : _data(data) {} // data is a 1D array

  ~MinFcn() {}

  double operator() (const std::vector<double> & params) const { // params is a 1D array
    //      f = cos(3.0*x)*exp(-1.5*pow(y,1.2));
    double X2 = 0.0;
    for (int i=0;i<_data[0].size();i++) {
      double x = _data[0][i];
      //double y = _data[1][i];
      double f = params[0]*x+params[1]; //params[0]cos(params[1]*x)*exp(-params[2]*pow(y,params[3]));
      X2 += (_data[1][i]-f)*(_data[1][i]-f);//(_data[2][i]-f)*(_data[2][i]-f); // chi squared value
    //cout << "X2 = " << X2 << endl;
    return X2;

  // set to 1 for chi-sq and 0.5 for log-likelihood
  double Up() const {return 1.0;}

}; // end of class MinFcn

using namespace std;

int main()
    vector< vector<double> > data(2);
    data[0].push_back(1.0); //generated some fake data to see if I get errors
    MinFcn fcn(data);
    vector<double> params(2,1.0); // 2 elements w/ values 1.0
    vector<double> err(2,0.1);    // read what this is (initial step size?)
    MnMigrad migrad(fcn, params, err);
    FunctionMinimum minParams = migrad();
    cout << data[0][0] << endl;
    return 0;

But when I try to compile I get a lot of errors of this type.

> C:/root_v5.34.36/include/Minuit2/MnApplication.h:48: undefined reference to `vtable for ROOT::Minuit2::MnApplication'

Can anybody tell me what can possibly be wrong?


You need to add -lMinuit2 to the list of linked libraries.

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

Thanks for your answer. To be very clear, I am using CodeBlocks in Windows, not Linux. I have the Minuit2 libraries in a folder whose path is


I included this library by going into Seetings -> Compiler -> Linker settings and adding the absolute path to the above library. Is that not the right way of doing it? I also included all the headers to the directories tab in a similar way.