# Creating a user application with ROOT

Using the example of creating and displaying a canvas, the following shows how you can create a standalone user application based on ROOT libraries.

Three different kind of standalone user applications are presented:

## A simple code example

With the following code a canvas is drawn (→ see also Graphics):

Figure: A simple canvas.

A C++ standalone program should be created with this code.

Note

If you use this code in a ROOT macro (→ see ROOT macros and shared libraries), you can only execute it with ROOT.

## Generating a PDF file

A C++ standalone program contains the main() function, the starting point for the application execution. For this reason, create a C++ file that you can compile.

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 the demo1.cxx file as follows :

The equivalent command on Windows is:

Then you can run the program as follows:

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.

## 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 the demo2.cxx file as follows :

The equivalent command on Windows is:

Then you can run the program as follows:

## Getting ROOT prompt

You can use TRint to create an environment provides an interface to the windows manager and eventloops 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 the demo3.cxx file as follows :

The equivalent command on Windows is:

Then you can run the program as follows: