2

Can I build/get static library (.a files instead of .so files) of tensorflow C API? I need to include/link tensorflow c api in my C++ software xyz and then I build shared library xyz.so that will be sent to other party. The other party should be able to run xyz.so without installing/building tensorflow.

fisakhan
  • 704
  • 1
  • 9
  • 27
  • `Can I build` what have you tried? What research did you do? What did it resulted it? Did you even see https://github.com/tensorflow/tensorflow/issues/28388 ? `other party should be able to run xyz.so without installing/building tensorflow` Why do you need a static library for that? Typically I see `LD_PRELOAD` used. You are asking XY question, no? – KamilCuk Mar 26 '21 at 09:06

2 Answers2

0

Download tensorflow c api and link .so files using CMakeLists.txt file.

fisakhan
  • 704
  • 1
  • 9
  • 27
0

I have gotten some things to work by compiling Tensorflow with the following bazel command:

bazel build --config=monolithic -j 1 //tensorflow:libtensorflow.so

And then linking together the object files with libtool for MacOS:

libtool -static -o libtensorflow_arm64_libtool_SO3.a $(cat bazel-bin/tensorflow/libtensorflow_cc.so.*.params | sed -e 's!-Wl,-force_load,!!' | grep -e '\.a$' -e '\.lo$' | sort -t: -u -k1,1)

Or ar for linux:

ar -cr libtensorflow.a $(cat bazel-bin/tensorflow/libtensorflow_cc.so.*.params | grep '\.o$')

I have not figured out all the details, but this does make at least version control and tensor allocation work.

EDIT:

In the end I opted for going with TFLite as it supports almost all TF operations and have Cmake support for building static libraries. For the full solution see this thread: Has anyone experience in building a static library for the Tensorflow C++ API?

Maxxxxxx
  • 31
  • 5