effbiae
effbiae

Reputation: 1157

How to build the c library for tensorflow

I've been through the steps to build tensorflow and it's working in python. Now how do I BUILD the C tensorflow library I want to use?

$ gcc -I../tensorflow -ltensorflow g.c
/usr/bin/ld: cannot find -ltensorflow
collect2: error: ld returned 1 exit status

Upvotes: 2

Views: 3568

Answers (2)

nessuno
nessuno

Reputation: 27070

There are 2 libraries you have to build:

  • libtensorflow_framework.so
  • libtensorflow.so

To build them you have to use bazel

bazel build //tensorflow:libtensorflow_framework.so
bazel build //tensorflow:libtensorflow.so

Once the build process of both libraries ends, you have to make the linker aware of where these libraries are, hence you have to upgrade the LIBRARY_PATH and the LD_LIBRARY_PATH accordingly.

TENSORFLOW_LIB = "/path/of/tensorflow/bazel-bin/tensorflow/"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${TENSORFLOW_LIB}`
export LIBRARY_PATH=${LIBRARY_PATH}:${TENSORFLOW_LIB}

Upvotes: 0

ash
ash

Reputation: 6751

To build the C library from source, follow most of the instructions for building TensorFlow from source, except that instead of building the pip package, build the tarball that packages the shared libraries and C API header file:

bazel build -c opt //tensorflow/tools/lib_package:libtensorflow

This will produce a tarball in:

bazel-bin/tensorflow/tensorflow/tools/lib_package/libtensorflow.tar.gz

More details in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/lib_package/README.md

The release binaries are built using the process described above.

Hope that helps.

Upvotes: 7

Related Questions