Use openturns in a c++ program

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)

From this file in the source, I tried this :

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

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

                 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 :

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

I get the following error :

/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…)

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

1 Like