Reputation: 802
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.
Upvotes: 3
Views: 581
Reputation: 71
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?
Upvotes: 1
Reputation: 802
Download tensorflow c api and link .so files using CMakeLists.txt file.
Upvotes: 0