# How to compile my code

**URL:** <https://root-forum.cern.ch/t/how-to-compile-my-code/32780>\
**Category:** Newbie\
**Created:** [February 18, 2019, 11:41am UTC](https://root-forum.cern.ch/t/how-to-compile-my-code/32780 "2019-02-18T11:41:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ACalcaterra](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@ACalcaterra](https://root-forum.cern.ch/u/ACalcaterra)\
**Post date:** [February 18, 2019, 11:41am UTC](https://root-forum.cern.ch/t/how-to-compile-my-code/32780/1 "2019-02-18T11:41:26Z")

</div>

Hi,  
the great thing about ROOT is that it keeps making you a newbie every few years.  
I used to be able have a working macro for ROOT _and_ a compilable version that would have run on its own:

```auto
#ifdef __CINT__ 

void wth() { // do it easy

#else
#include "TH1F.h"

  int main () { // do it fast

#endif

  TH1F* aPointer = new TH1F("a","a",10,0.,1.);
  aPointer->Draw();
  return 0;
}

```

but I have now ROOT 6.14 and it doesn’t work, **CINT** is undefined:  
root [0] .X wth.cc  
warning: cannot find function ‘wth()’; falling back to .L

Looking at post, I found one that seemed to suggest to use **ROOTCLING** instead, but it doesn’t seem to work either.

Oh, and it doesn’t compile too!

```auto
 set command = "g++ -g -I$ROOTSYS/include `root-config --libs` $1 -o $program"
echo -n "compiling......."
$command
echo "done!"

compiling......./tmp/cc8kpW7w.o: In function `main':
/home/acal/SHiP_tb2018/wth.cc:12: undefined reference to `TH1F::TH1F(char const*, char const*, int, double, double)'
/home/acal/SHiP_tb2018/wth.cc:12: undefined reference to `TObject::operator delete(void*)'
/tmp/cc8kpW7w.o: In function `__static_initialization_and_destruction_0(int, int)':
/cern/root/include/TVersionCheck.h:42: undefined reference to `TVersionCheck::TVersionCheck(int)'
/tmp/cc8kpW7w.o: In function `TObject::operator new(unsigned long)':
/cern/root/include/TObject.h:152: undefined reference to `TStorage::ObjectAlloc(unsigned long)'
collect2: error: ld returned 1 exit status
done!

```

any help much appreciated!

---

<div class="post-metadata">

**Author:** ![ACalcaterra](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@ACalcaterra](https://root-forum.cern.ch/u/ACalcaterra)\
**Post date:** [February 18, 2019, 11:43am UTC](https://root-forum.cern.ch/t/how-to-compile-my-code/32780/2 "2019-02-18T11:43:34Z")

</div>

Here’s another funny things, the posting process removed the double underscores before and after CINT and ROOTCLING. But they are there, trust me…

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 18, 2019, 11:58am UTC](https://root-forum.cern.ch/t/how-to-compile-my-code/32780/3 "2019-02-18T11:58:05Z")

</div>

```auto
#include "TH1.h"

// "ROOT Script" entry point.
void wth() {
  TH1F *aPointer = new TH1F("a", "a", 10, 0., 1.);
  aPointer->Draw();
}

#if !defined( __CINT__ ) && !defined( __CLING__ ) && !defined( __ACLIC__ )
// "Standalone Application" entry point.
// `root-config --cxx --cflags` -o wth wth.cc `root-config --libs`
int main()
{
  wth();
  return 0;
}
#endif /* !defined( __CINT__ ) && !defined( __CLING__ ) && !defined( __ACLIC__ ) */

```

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

---

<div class="post-metadata">

**Author:** ![ACalcaterra](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@ACalcaterra](https://root-forum.cern.ch/u/ACalcaterra)\
**Post date:** [February 18, 2019, 1:08pm UTC](https://root-forum.cern.ch/t/how-to-compile-my-code/32780/4 "2019-02-18T13:08:31Z")

</div>

Thanks! Also for the “root-config -cxx…” recipe. I should have known about that…

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [February 18, 2019, 1:13pm UTC](https://root-forum.cern.ch/t/how-to-compile-my-code/32780/5 "2019-02-18T13:13:11Z")

</div>

Hi,  
a bit of context: the big change between ROOT5 and ROOT6 was the switch from a homebrew C++ interpreter (CINT) to a clang-based interpreter (better standard compliance, support for all C++ features and newer C++ standards, etc).

With that switch, ` __CINT__ ` was substituted by ` __CLING__ `

Cheers,  
Enrico

P.S. In ROOT6, I usually write ROOT tutorials just like this (works both as macro and as compiled code):

```auto
// wth.cpp

#include "TH1.h"

void wth() {
  TH1F *aPointer = new TH1F("a", "a", 10, 0., 1.);
  aPointer->Draw();
}

int main()
{
  wth();
  return 0;
}

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 18, 2019, 1:15pm UTC](https://root-forum.cern.ch/t/how-to-compile-my-code/32780/6 "2019-02-18T13:15:56Z")

</div>

[My macro is supposed to be equally valid for both versions, ROOT 5 and ROOT 6, hence I explicitly use both defines.](https://root-forum.cern.ch/t/root-6-cling-rootcling-replacements-for-cint-makecint-and-aclic-macros/27698)
