Problem to have an .exe

Hi to all,

I have a problem using ROOT and MS Visual Studio 2008:

My OS is windows SETTE (but I have the same problem on WinXP); I think to have config right ROOT (I add on the Environment Variables: include -> “C:\root\include”, lib -> “C:\root\lib”, PATH -> “c:\root\bin”, ROOTSYS -> “c:\root”);

My compiler is MS Visual Studio 2008, and I have set in the project option:
on property page -> C++ -> General -> additional include path -->>$(ROOTSYS)/include
on property page -> Linker -> Input -> additional dependencies -->> $(ROOTSYS)/lib/*.lib

if I try to compile a simple macro as:

#include "TCanvas.h"
using namespace std;

void HelloRoot()
cout << “Hello Root” << endl;
new TCanvas();
I have the following errors:

[quote]------ Build started: Project: root04, Configuration: Release Win32 ------
Performing Pre-Build Event…
MSVCRT.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
C:\Users\chicco\Documents\Visual Studio 2008\Projects\root04\Release\root04.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Users\chicco\Documents\Visual Studio 2008\Projects\root04\root04\Release\BuildLog.htm"
root04 - 2 error(s), 0 warning(s)[/quote]
where are my errors???



what are you trying to do? Instead of using Visual Studio to build, you could simply start ROOT and type .L HelloRoot.C+ (or whatever the source file is containg HelloRoot()). Note the “+” at the end which will tell ROOT to compile and link your code.

Cheers, Axel.


Please try like this:

#include <iostream> 
#include "TApplication.h"
#include "TCanvas.h" 
using namespace std; 

void HelloRoot() 
   cout << "Hello Root" << endl; 
   new TCanvas(); 

int main(int argc, char **argv) 
   TApplication theApp("My First App", &argc, argv); 
   return 0; 

For info (and this is not related to ROOT), the function main() is needed when creating a standalone executable (it is the application main entry point).
And to create a ROOT standalone application, you must create a TApplication.



I believe this is true only if you are using graphics. If you are not trying to display any graphics (e.g., reading and writing root trees without displaying any canvases), then you don’t need to create a TApplication.


Hi and thank for reply so quickly;

for Axel:
well, I tried to use “.L”, but I receive these error:

[quote]ROOT 5.22/00 (trunk@26997, Jan 05 2009, 10:56:00 on win32)

CINT/ROOT C/C++ Interpreter version 5.16.29, Jan 08, 2008
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .L HelloRoot.c+
Info in TWinNTSystem::ACLiC: creating shared library c:\Users\chicco\MyWorks\p
’cl’ is not recognized as an internal or external command,
operable program or batch file.
Error: external preprocessing failed. (0)
!!!Removing c:\Users\chicco\MyWorks\pendolo\HelloRoot_c_ACLiC_dict.cxx c:\Users
chicco\MyWorks\pendolo\HelloRoot_c_ACLiC_dict.h !!!
Error: C:\root\bin\rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
’cl’ is not recognized as an internal or external command,
operable program or batch file.
root [1][/quote]
so I thougth these command was valid only under linux…
Have I some error in ROOT’s configuration???

for bellenot:
:blush: I forgotten the principles of programmation… it seems to work: tomorrow I try to execute in a computer without ROOT…

thanks so much,

[quote]‘cl’ is not recognized as an internal or external command,
[/quote]The microsoft compiler is not available on the PATH in the ‘shell’ your start root.exe in. (I.e. before starting root.exe you may need to execute vcvars32.bat or similar).



I have tried that in MS Windows is possible to compile from command line only from the MS Visual Studio Command Prompt (MSVS2008->VSTools->CommandPrompt)… from here the command is recognized.

now I have a new error windows:

[quote]Runtime Error!
Program: C:\root\bin\root.exe
An application has made an attempt to load the C runtime library incorrectly.
please contact the application’s support team for more information.[/quote]
I have add to my system the dformd.dll, MSVCP71.dll, MSVCR71.dll and the MSFRT40.dll ( and also the MSVCP90.dll and MSVCR90.dll

using the scheme suggested by bellenot, and compiling using MSVS, I obtain a .exe that work on my pc, but on a pc without ROOT and with WinXP it don’t start: an error said “missing libCore.dll”…

is this the correct way to have a programm that run without ROOT installed???

thanks to all,



To run ROOT based applications, you have to install ROOT.

Cheers, Bertrand.