Hello, I am having trouble compiling a stand alone console application in VC++ 10, windows 7, root version 5.34. My code is below. I can compile just fine when no functions are called. As soon as I call a function such as the TFile constructor, I get a “error LNK2001: unresolved external symbol”. I have set the include path and link path correctly in the VC++ options menu for the project. Intellisense recognized the functions when I write them. Somehow, though, when I compile there is a disconnect where the compiler can’t find the libraries. I have tried manually including all the libraries in the additional include field in the linker options. This does not solve the problem.
I feel like there is something I am missing here. I have another program that I didn’t build that makes extensive use of the root libraries without this problem and it compiles just fine.
Any help would be tremendous I am under alot of time pressure.
#include "stdafx.h"
#include "w32pragma.h"
#include "TApplication.h"
//File handling
#include "TObject.h"
#include "TROOT.h"
#include "TKey.h"
#include "TFile.h"
#include "TSystem.h"
#include "TTree.h"
//RooFit
#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "TCanvas.h"
#include "RooPlot.h"
#include "TAxis.h"
//using namespace RooFit;
int main(int argc, _TCHAR* argv[])
{
TFile *f = new TFile("result.root","recreate","f",0);
//
//
//// Declare variables x,mean,sigma with associated name, title, initial value and allowed range
//RooRealVar x("x","x",-10,10) ;
//RooRealVar mean("mean","mean of gaussian",1,-10,10) ;
//RooRealVar sigma("sigma","width of gaussian",1,0.1,10) ;
//
//// Build gaussian p.d.f in terms of x,mean and sigma
//RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;
//
//// Construct plot frame in 'x'
//RooPlot* xframe = x.frame(Title("Gaussian p.d.f.")) ;
return 0;
}
I managed to get it to compile by explicitly including the .lib library files I needed in the Project Properties->linker->Input->Additional Dependencies.
However, This seems to be a clumsy way to do things. I was under the impression that I didn’t need to manually specify the .lib files if I included the file path to those libraries. I thought the linker would just find the symbols in those files.
Does anybody know why vc++ does not seem to find the libraries for root by itself?
TBH, that’s one of the many reasons why C++ should really, really, REALLY get a module system.
I mean, Fortran has had one since 2003
(And Go, too as well, so you don’t have to muck around with linkopts and include paths anymore)