Install TensorFlow for C

View on Run in Google Colab View source on GitHub Download notebook

TensorFlow provides a C API that can be used to build bindings for other languages. The API is defined in c_api.h and designed for simplicity and uniformity rather than convenience.

Nightly libtensorflow C packages

libtensorflow packages are built nightly and uploaded to GCS for all supported platforms. They are uploaded to the libtensorflow-nightly GCS bucket and are indexed by operating system and date built. For MacOS and Linux shared objects, there is a script that renames the .so files versioned to the current date copied into the directory with the artifacts.

Supported Platforms

TensorFlow for C is supported on the following systems:

  • Linux, 64-bit, x86
  • macOS, Version 10.12.6 (Sierra) or higher
  • Windows, 64-bit x86


Download and extract

TensorFlow C libraryURL
Linux CPU only
Linux GPU support
macOS CPU only
Windows CPU only
Windows GPU only

Extract the downloaded archive, which contains the header files to include in your C program and the shared libraries to link against.

On Linux and macOS, you may want to extract to /usr/local/lib:

wget -q --no-check-certificate${FILENAME}
sudo tar -C /usr/local -xzf ${FILENAME}


On Linux/macOS, if you extract the TensorFlow C library to a system directory, such as /usr/local, configure the linker with ldconfig:

sudo ldconfig /usr/local/lib

If you extract the TensorFlow C library to a non-system directory, such as ~/mydir, then configure the linker environmental variables:


export LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib


export LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib


Example program

With the TensorFlow C library installed, create an example program with the following source code (hello_tf.c):

%%writefile hello_tf.c
#include <stdio.h>
#include <tensorflow/c/c_api.h>

int main() {
  printf("Hello from TensorFlow C library version %s\n", TF_Version());
  return 0;
Writing hello_tf.c


Compile the example program to create an executable, then run:

gcc hello_tf.c -ltensorflow -o hello_tf

Hello from TensorFlow C library version 2.15.0

If the program doesn't build, make sure that gcc can access the TensorFlow C library. If extracted to /usr/local, explicitly pass the library location to the compiler:

gcc -I/usr/local/include -L/usr/local/lib hello_tf.c -ltensorflow -o hello_tf

Hello from TensorFlow C library version 2.15.0

Build from source

TensorFlow is open source. Read the instructions to build TensorFlow's C library from source code.