# Creating ROOT executable with input arguments

**URL:** <https://root-forum.cern.ch/t/creating-root-executable-with-input-arguments/57477>\
**Category:** Newbie\
**Created:** [December 9, 2023, 7:38pm UTC](https://root-forum.cern.ch/t/creating-root-executable-with-input-arguments/57477 "2023-12-09T19:38:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelb91](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/samuelb91/32/35418_2.png) [@samuelb91](https://root-forum.cern.ch/u/samuelb91)\
**Post date:** [December 9, 2023, 7:38pm UTC](https://root-forum.cern.ch/t/creating-root-executable-with-input-arguments/57477/1 "2023-12-09T19:38:05Z")

</div>

Hi there,

I’m pretty new to ROOT, and not sure if there’s a simple answer to this, but I figured this forum would be a good place to ask. If I’m mistaken, apologies in advance.

I have a ROOT macro. I can run the macro with an input argument of a configuration file using the ROOT interpreter, but the execution of my program is pretty slow. What I would like to do is compile my macro into an executable that has the ability to read in an argument so I can pass different configuration files.

Any advice is appreciated - I am using version 6.16.00.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [December 10, 2023, 4:10am UTC](https://root-forum.cern.ch/t/creating-root-executable-with-input-arguments/57477/2 "2023-12-10T04:10:30Z")

</div>

Just write the macro with “main” as your main function (instead of using the same as the file name) and pass/use the arguments the same way as for any c++ program --and don’t forget to `#include` all the needed headers in your code.  
[https://www.google.com/search?q=c%2B%2B+command+line+arguments](https://www.google.com/search?q=c%2B%2B+command+line+arguments)

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [December 11, 2023, 10:38am UTC](https://root-forum.cern.ch/t/creating-root-executable-with-input-arguments/57477/3 "2023-12-11T10:38:38Z")

</div>

> but the execution of my program is pretty slow.

You can simply using `ACLiC` to automatically compile your code by adding a trailing `+` to you script name So replacing something like:

```auto
root.exe 'myscript.C(args)`
or
root [] .x myscript.C(args)

```

with

```auto
root.exe myscript.C+(args)
or
root [] .x myscript.C+(args)

```

---

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [December 14, 2023, 8:16pm UTC](https://root-forum.cern.ch/t/creating-root-executable-with-input-arguments/57477/4 "2023-12-14T20:16:49Z")

</div>

Hello,

As people has give you the answer, I just want to add a bit more detail.

Here is an example of valid C macro (file name is `draw_hist.C`)

```auto
#include <cstdio>
#include <cstdlib>
#include <TH1D.h>
#include <TCanvas.h>

// use `int main` if you compile with gcc
void main ( int n_args, const char** args )
{
	int n_entries = 10;
	if ( n_args > 1 ) n_entries = atoi( args[1] );
	TH1D* hist = new TH1D( "hist", "hist", 10, 0, 10 );
	for ( int i=0; i<n_entries; i++ )
		hist -> Fill( 3.4 );
	TCanvas* canvas = new TCanvas( "canvas", "", 400, 300 );
	canvas -> cd( );
	hist -> Draw( "hist" );
	canvas -> SaveAs( "plot_hist.png" );
	canvas -> Close( );
	return 0;
}

```

Then to compile it, you can do:

```auto
$ g++ -o draw_hist draw_hist.C $( root-config --libs --cflags )

```

and then run the compiled program by

```auto
$ ./draw_hist 100

```

Hope this help,  
Hoa.

---

<div class="post-metadata">

**Author:** ![samuelb91](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/samuelb91/32/35418_2.png) [@samuelb91](https://root-forum.cern.ch/u/samuelb91)\
**Post date:** [December 21, 2023, 3:17pm UTC](https://root-forum.cern.ch/t/creating-root-executable-with-input-arguments/57477/5 "2023-12-21T15:17:51Z")

</div>

Thanks for the answer, this is exactly what I needed!
