# Creating a user application with ROOT

Starting from a simple ROOT macro creating and displaying a canvas, this section shows how to create a standalone user application based on ROOT libraries.

Three different kind of standalone user applications are presented:

## The simple ROOT macro

The following code can be executed interactively at the ROOT prompt:

Figure: A simple canvas.

Now, let’s see how to create a standalone application with this simple code.

## Batch example generating a PDF file

A C++ standalone application must contain the main() function, the starting point for the application execution.

The first lines of the C++ file include ROOT header files. The names of the ROOT header files are almost always the same as the class names (here TF1 and TCanvas ).

Save the code in a file, for example as demo1.cxx.

On Linux and MacOS compile and run the demo1.cxx file as following :

The equivalent command on Windows is:

> cl -nologo -MD -GR -EHsc demo1.cxx -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGpad.lib libHist.lib
> demo1


Note

You can use root-config --cflags to be sure to use the correct compiler flags (Debug vs Release)

The following message is displayed:

The demo1.pdf file is saved in the current working directory. The pdf file contains the plot of the f1 function.

## Interactive example displaying a canvas

Use TApplication to display the output on a screen.

TApplication creates a ROOT application environment that provides an interface to the windowing system event loops and event handlers.

To run the canvas as a standalone application you must create a TApplication object. Calling the Run() method starts the event loop.

Save the code in a file, for example as demo2.cxx.

On Linux and MacOS compile and run the demo2.cxx file as following :

The equivalent command on Windows is:

> cl -nologo -MD -GR -EHsc demo2.cxx -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGpad.lib libHist.lib
> demo2


Note

You can use root-config --cflags to be sure to use the correct compiler flags (Debug vs Release)

## Example using ROOT prompt

You can use TRint to create an environment provides an interface to the windows manager and event loop via the inheritance of TApplication . In addition TRintprovides an interactive access to the Cling C++ interpreter via the command line.

Save the code in a file, for example demo3.cxx.

On Linux and MacOS compile and run the demo3.cxx file as following :

The equivalent command on Windows is:

> cl -nologo -MD -GR -EHsc demo3.cxx -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGpad.lib libHist.lib
> demo3


Note

You can use root-config --cflags to be sure to use the correct compiler flags (Debug vs Release)