Problems Linking in VC++

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;
}

Hi,

You have to specify the libraries to link your application with. How do you compile/link your code?
For example, you can do something like this:

cl -nologo -MD -GR -EHsc yourfile.cxx -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libRIO.lib libRoofit.lib libGpad.lib

Cheers, Bertrand.

The linker code is generated by VC++. You can see in the two command line generations that the c:\root\include and c:\root\lib are there.

The include command line is:

/I"C:\root\include" /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D “WIN32” /D “NDEBUG” /D “_CONSOLE” /D “_UNICODE” /D “UNICODE” /Gm- /EHsc /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Release\rooStatsTest.pch" /Fa"Release" /Fo"Release" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue

The linker command line is:

/OUT:“c:\Users\ASGatton\Documents\Visual Studio 2010\Projects\rooStatsTest\Release\rooStatsTest.exe” /INCREMENTAL:NO /NOLOGO /LIBPATH:“C:\root\lib” “kernel32.lib” “user32.lib” “gdi32.lib” “winspool.lib” “comdlg32.lib” “advapi32.lib” “shell32.lib” “ole32.lib” “oleaut32.lib” “uuid.lib” “odbc32.lib” “odbccp32.lib” /MANIFEST /ManifestFile:“Release\rooStatsTest.exe.intermediate.manifest” /ALLOWISOLATION /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /DEBUG /PDB:“c:\Users\ASGatton\Documents\Visual Studio 2010\Projects\rooStatsTest\Release\rooStatsTest.pdb” /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /PGD:“c:\Users\ASGatton\Documents\Visual Studio 2010\Projects\rooStatsTest\Release\rooStatsTest.pgd” /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

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?

Cheers,

-Ave

Hi,

This is the way all the compilers/linker work… You have to explicitly tell which libraries to use

Cheers, Bertrand.

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 :slight_smile:
(And Go, too as well, so you don’t have to muck around with linkopts and include paths anymore)

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