# Can not compile my C++ code including headers from ROOT

**URL:** <https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [April 18, 2023, 11:23am UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542 "2023-04-18T11:23:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![grattoni](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@grattoni](https://root-forum.cern.ch/u/grattoni)\
**Post date:** [April 18, 2023, 11:23am UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/1 "2023-04-18T11:23:13Z")

</div>

* * *

\_ROOT Version: 6.26/06  
_Platform:_ macOS 12.4  
_Compiler:_ g++ / clang ?

* * *

I can compile the root macros written in C with `root /path/to/mymacro.c` command just fine but I can’t compile a C++ file including headers from ROOT. I am using bash.

A basic cpp file like this

```auto
(with or without) #include <iostream> 
#include "TTree.h"
#include "TFile.h"

void trying(){

    std::cout << "Hello World!" << std::endl;

};

int main(){
    
    trying();

    return 0;
}

```

Does not compile. It gives many errors.

I am trying to write a C++ program where I get a TSV file from the user, in which the columns are converted to vectors in another cpp program I wrote ( which works fine), and I want to convert those vectors to TTree’s with a new cpp file I linked together with #include “giant.h” .

I used the prompt `g++ all_of_the_files_I_want_to_compile_.cpp -o output $(root-config --libs)` and `g++ all_the_files.cpp -o output $(root-config --cflags)` and `g++ myfile.c I$(root-config --incdir) -o output ` and all the other configurations I can’t remember now.

**PLZ HELP.**  
I am a noob idk what to do at this point!

---

<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:** [April 18, 2023, 11:35am UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/2 "2023-04-18T11:35:22Z")

</div>

`$(root-config --cxx --cflags) -O2 -Wall -Wextra -o output all_the_files.cpp $(root-config --libs)`

---

<div class="post-metadata">

**Author:** ![grattoni](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@grattoni](https://root-forum.cern.ch/u/grattoni)\
**Post date:** [April 18, 2023, 12:11pm UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/3 "2023-04-18T12:11:25Z")

</div>

Thank you for your prompt response.

When I run the command you gave with all the source files, I get the variations of the following error:

```auto
ld: warning: ignoring file /usr/local/Cellar/root/6.26.06_2/lib/root/libROOTDataFrame.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

```

plus this:

```auto
Undefined symbols for architecture arm64:
  "TVersionCheck::TVersionCheck(int)", referenced from:
      __GLOBAL__ sub_I_functions.cpp in functions-e54aa0.o
      __GLOBAL__ sub_I_interface.cpp in interface-7ec9d8.o
      __GLOBAL__ sub_I_main.cpp in main-ac668d.o
ld: symbol(s) not found for architecture arm64

```

I haven’t used the functions dependent on the ROOT headers in my program yet. When I remove TFile.h and TTree.h from the` giant.h` file that every source file depends on and run the exact same thing with:

```auto
g++ allsource.cpp -o output

```

I can get the output file with no problems.

---

<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:** [April 18, 2023, 12:13pm UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/4 "2023-04-18T12:13:15Z")

</div>

Looks like you have ROOT binaries for an “x86\_64” while your machine is an “arm64”.

---

<div class="post-metadata">

**Author:** ![grattoni](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@grattoni](https://root-forum.cern.ch/u/grattoni)\
**Post date:** [April 18, 2023, 12:14pm UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/5 "2023-04-18T12:14:29Z")

</div>

Do I have to uninstall and install the correct version of ROOT? If so, may I ask how do I find it? I am new to programming C++ and ROOT.

---

<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:** [April 18, 2023, 12:15pm UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/6 "2023-04-18T12:15:43Z")

</div>

> **[Releases](https://root.cern/install/all_releases/)**
>
> Data Analysis Framework

> **[Installing ROOT](https://root.cern/install/)**
>
> Data Analysis Framework

---

<div class="post-metadata">

**Author:** ![grattoni](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@grattoni](https://root-forum.cern.ch/u/grattoni)\
**Post date:** [April 18, 2023, 12:17pm UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/7 "2023-04-18T12:17:16Z")

</div>

Thank you very much! I wasn’t able to solve this problem for the last couple days.

---

<div class="post-metadata">

**Author:** ![grattoni](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@grattoni](https://root-forum.cern.ch/u/grattoni)\
**Post date:** [April 18, 2023, 2:09pm UTC](https://root-forum.cern.ch/t/can-not-compile-my-c-code-including-headers-from-root/54542/9 "2023-04-18T14:09:06Z")

</div>

So, I rebuilded ROOT a few times using different sources, which I probably made a mistake with because I kept getting the same error. Adding `-arch x86_64` at the end of the command you shared solved my problem for some reason:

`$(root-config --cxx --cflags) -O2 -Wall -Wextra -o output all_the_files.cpp $(root-config --libs) -arch x86_64`

Leaving this here if anyone else needs it.

Thank you very much.
