mercredi 9 février 2022

Build Tensorflow >2.4.* with c++11 compatibility

The idea is to build Tensorflow >2.4.* (tensorflow:libtensorflow_cc.so & tensorflow:install_headers) to use it in a C++ project compiled in C++11 standard.

After creating a Docker container on Ubuntu:16.04 with the rights dependencies and using gcc 7.5.0-3. I managed to successfully compile the library using the following command: bazel build --config=opt --config=cuda --config=monolithic --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow:libtensorflow_cc.so //tensorflow:install_headers

However the compiled library seems to be compiled with c++14 standard because it raise the following issue

    include/tensorflow/core/framework/tensor_types.h:176:25: error: use of ‘auto’ in lambda parameter declaration only available with ‘-std=c++14’ or ‘-std=gnu++14’
  176 |     auto all = [](const auto&... bool_vals) {
      |                         ^~~~

Changing my application from set(CMAKE_CXX_STANDARD 11) to set(CMAKE_CXX_STANDARD 14) also confirm that TensorFlow has been successfully compiled and is working. Changing C++ standard in my application is not an option yet.

After some checks, It seems that TensorFlow is built with C++14 by default. I tried to manually change the value of c++ from c++14 to c++11 without success. I also tried to compile TensorFlow using the library TensorFlow_CC from FloopCZ because it set the C++ standard for building and linking the library. But it also fails.

Issues on Github did not help me to solve my problem.

Any idea to compile Tensorflow and be able to use it in c++11 application? Is it even possible to run TensorFlow >2.4 on C++11?

Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire