# Use openturns in a c++ program

**URL:** <https://openturns.discourse.group/t/use-openturns-in-a-c-program/235>\
**Category:** Installation\
**Created:** [July 22, 2022, 8:33am UTC](https://openturns.discourse.group/t/use-openturns-in-a-c-program/235 "2022-07-22T08:33:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomas](https://openturns.discourse.group/u/thomas)\
**Post date:** [July 22, 2022, 8:33am UTC](https://openturns.discourse.group/t/use-openturns-in-a-c-program/235/1 "2022-07-22T08:33:22Z")

</div>

Hi !

I discovered that Openturns is also a c++ library.  
I installed on my computer the deb `libopenturns-dev` and `libopenturns0.15`, but I did not manage to find how to include it in a c++ program, and I did not find a page about it in the documentation, (only how to [install it](http://openturns.github.io/openturns/latest/install.html#debian-ubuntu))

From [this file](https://github.com/openturns/openturns/blob/master/lib/src/main.cxx) in the source, I tried this :

```auto
#include "openturns/OT.hxx"
int main(int, char *[]) {
    return 0;
}

```

At the compilation (without any glag) using g++ I get :

```nohighlight
                 from /usr/include/openturns/FieldImplementation.hxx:29,
                 from /usr/include/openturns/Field.hxx:25,
                 from /usr/include/openturns/FunctionImplementation.hxx:28,
                 from /usr/include/openturns/Function.hxx:25,
                 from /usr/include/openturns/LinearLeastSquares.hxx:28,
                 from /usr/include/openturns/OTBaseMetaModel.hxx:25,
                 from /usr/include/openturns/OTBase.hxx:26,
                 from /usr/include/openturns/OT.hxx:51,
                 from ot.cpp:1:
/usr/include/tbb/task_scheduler_init.h:21:154: note: #pragma message: TBB Warning: tbb/task_scheduler_init.h is deprecated. For details, please see Deprecated Features appendix in the TBB reference manual.
   21 | #pragma message("TBB Warning: tbb/task_scheduler_init.h is deprecated. For details, please see Deprecated Features appendix in the TBB reference manual.")
      | ^
/usr/bin/ld : /tmp/ccuvdFRr.o : dans la fonction « tbb::interface7::task_arena::current_thread_index() » :
ot.cpp:(.text._ZN3tbb10interface710task_arena20current_thread_indexEv[_ZN3tbb10interface710task_arena20current_thread_indexEv]+0x9) : référence indéfinie vers « tbb::interface7::internal::task_arena_base::internal_current_slot() »
collect2: error: ld returned 1 exit status

```

How can I fix the compilation to use OT in a c++ program ?

Thanks

**EDIT :**  
After som research, I managed to compile with the following command : `g++ ot.cpp -ltbb -std=c++11`.  
Now I tried to declare a `Point` in the `main` function :

```auto
int main(int, char *[])
{
    OT::Point P;
}

```

I get the following error :

```auto
/usr/bin/ld : /tmp/ccBgGP0q.o : dans la fonction « main » :
ot.cpp:(.text+0x71) : référence indéfinie vers « OT::Point::Point() »
/usr/bin/ld : /tmp/ccBgGP0q.o : dans la fonction « OT::Object::Object() » :
ot.cpp:(.text._ZN2OT6ObjectC2Ev[_ZN2OT6ObjectC5Ev]+0xf) : référence indéfinie vers « vtable for OT::Object »

```

(among many errors of that kind, for other function where the reference is undefined…)

---

<div class="post-metadata">

**Author:** ![thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomas](https://openturns.discourse.group/u/thomas)\
**Post date:** [August 1, 2022, 3:27pm UTC](https://openturns.discourse.group/t/use-openturns-in-a-c-program/235/2 "2022-08-01T15:27:40Z")

</div>

Thanks to the chat from openturn website, I was given the solution : we just need to link openturns at compilation with the option `-lOT`
