Using ROOT in VC++ 2010 (easy code but a lot of problems)

I’m trying to use ROOT libraries in a very simple code, but I get a ton of errors. I’m on Windows 8, running VC++ 2010, and I’ve installed the VC++ 2010 MSI version of ROOT.

My code:

[code] #include
#include
#include
#include
#include “TLorentzVector.h”

using namespace std;

int main()
{
	TLorentzVector muon1;
	muon1.SetPtEtaPhiM(231.277,0.496237,-2.22082,0.1);

	cout<<muon1.Px();

	return 0;
}[/code]

Per another website’s suggestions, these are the steps I’ve done to link ROOT to VC++:

Property Pages>Config Properties>VC++ Directories>Library Directories: added $(root)\lib

Config Properties>C/C++>General>Additional Include Directories: added $(rootsys)\include

Config Properties>Linker>General>Additional Library Directories: added $(rootsys)\lib

Config Properties>Linker>Input>Additional Dependencies: included libPhysics.lib

error message in console:

1>------ Build started: Project: muonproject, Configuration: Debug Win32 ------ 1> Source.cpp 1>c:\root\include\tstring.h(503): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1>c:\root\include\tstring.h(506): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1>c:\root\include\tstring.h(524): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1>c:\root\include\tstring.h(535): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1>c:\root\include\tstring.h(543): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1>c:\root\include\tvector3.h(244): warning C4244: '=' : conversion from 'const Double_t' to 'Float_t', possible loss of data 1>c:\root\include\tvector3.h(245): warning C4244: '=' : conversion from 'const Double_t' to 'Float_t', possible loss of data 1>c:\root\include\tvector3.h(246): warning C4244: '=' : conversion from 'const Double_t' to 'Float_t', possible loss of data 1>c:\root\include\tlorentzvector.h(365): warning C4244: '=' : conversion from 'const Double_t' to 'Float_t', possible loss of data 1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall TVersionCheck::TVersionCheck(int)" (??0TVersionCheck@@QAE@H@Z) referenced in function "void __cdecl `dynamic initializer for 'gVersionCheck''(void)" (??__EgVersionCheck@@YAXXZ) 1>C:\Users\Jeffrey\documents\visual studio 2010\Projects\muonproject\Debug\muonproject.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Apparently using W32Pragma.h or something gets rid of a lot of these errors? I’m just trying to figure out why my code won’t run, as it’s simple enough. Also, I get this error message in the console: imgur.com/XGsnPQB

Thanks for the help guys, I really can’t find any other solutions online. Also, I’m a huge C++ noob if that wasn’t already apparent.

Hi,

I have no problem running your code compiled on the command line with:

cl -nologo -Z7 -MD -GR -EHsc test.cxx -I %ROOTSYS%\include /link -debug -LIBPATH:%ROOTSYS%\lib libCore.lib libPhysics.libSo please provide the complete project if you need help with it…

Cheers, Bertrand.

As said before, I’m a huge C++ noob. To Compile, I literally press ctrl+F5 in VC++, and I have no idea what the command line is. Could you please clarify?

Also, I’m not sure what you mean by complete project, because I only have Source.cpp and the code above is the only text in my Source file.

Thanks for the help,
jilikeslego

Hi,

Well, you probably created a project (or solution in MS language), right? So in this case you can zip the folder into which you created the solution, together with its files and sub-folders, if any.
And by “command line” I mean the “Visual Studio Command Prompt (2010)” from the Visual Studio menu (the exact location depends on the exact version)
And if you have no idea what I’m talking about, the I would suggest to read some of the many tutorials and examples you can find on the web, or in the book stores… :wink:

Cheers, Bertrand.

Bellenot you’re probably right, I really should read a C++ book. The most in-depth tutorial I’ve gone through was on the Cplusplus website: cplusplus.com/doc/tutorial/

I finally got it to work. I still can’t figure out why the code compiles in cmd but not through the actual Visual Studio client though.

Thanks though!