# Problem with gcc flag/file order when compiling against ROOT libraries

**URL:** <https://root-forum.cern.ch/t/problem-with-gcc-flag-file-order-when-compiling-against-root-libraries/36684>\
**Category:** ROOT\
**Created:** [November 5, 2019, 9:52am UTC](https://root-forum.cern.ch/t/problem-with-gcc-flag-file-order-when-compiling-against-root-libraries/36684 "2019-11-05T09:52:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xaunther](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaunther/32/21809_2.png) [@Xaunther](https://root-forum.cern.ch/u/Xaunther)\
**Post date:** [November 5, 2019, 9:52am UTC](https://root-forum.cern.ch/t/problem-with-gcc-flag-file-order-when-compiling-against-root-libraries/36684/1 "2019-11-05T09:52:57Z")

</div>

Hello, I’m having quite a silly problem while trying to compile a very simple code using ROOT libraries. I’ve reduced the problem to something as simple as:

```auto
#include <iostream>
#include "TFile.h"
    
int main()
{
    std::cout << "Hello world" << std::endl;
    return 0;
}

```

Where I’m just naively importing some ROOT class.  
Then I try to compile using the required flags (and more)

```
`c++ `root-config --cflags --libs` code.C`

```

But I get the following error:

```auto
/tmp/cc92ofKo.o: In function `__static_initialization_and_destruction_0(int, int)':
code.C:(.text+0x86): undefined reference to `TVersionCheck::TVersionCheck(int)'
collect2: error: ld returned 1 exit status

```

However, if I just happen to place the source code before the flags, it works fine:

```auto
c++ code.C `root-config --cflags --libs`

```

Why does this happens? It is a problem since CMake automatically places the flags before the source file, and fails to build. I’ve seen this problem reported, but with no further insight provided…

_ROOT Version:_ 6.18/04  
_Platform:_ Ubuntu 18.04  
_Compiler:_ c++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.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:** [November 5, 2019, 10:41am UTC](https://root-forum.cern.ch/t/problem-with-gcc-flag-file-order-when-compiling-against-root-libraries/36684/2 "2019-11-05T10:41:50Z")

</div>

Search for “`--as-needed`” in [man ld -\> Command Line Options](https://sourceware.org/binutils/docs/ld/Options.html)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [November 19, 2019, 10:42am UTC](https://root-forum.cern.ch/t/problem-with-gcc-flag-file-order-when-compiling-against-root-libraries/36684/3 "2019-11-19T10:42:00Z")

</div>

Closed on November 19, 2019, 10:42am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
