# Install TensorFlow for C

|---|---|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png)View on TensorFlow.org](https://www.tensorflow.org/install/lang_c) | [![](https://www.tensorflow.org/images/colab_logo_32px.png)Run in Google Colab](https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/install/lang_c.ipynb) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png)View source on GitHub](https://github.com/tensorflow/docs/blob/master/site/en/install/lang_c.ipynb) | [![](https://www.tensorflow.org/images/download_logo_32px.png)Download notebook](https://storage.googleapis.com/tensorflow_docs/docs/site/en/install/lang_c.ipynb) |

TensorFlow provides a C API that can be used to build
[bindings for other languages](https://github.com/tensorflow/docs/tree/master/site/en/r1/guide/extend/bindings.md).
The API is defined in
[`c_api.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/c/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](https://storage.googleapis.com/libtensorflow-nightly)
and are indexed by operating system and date built. For MacOS and Linux shared
objects, there is a
[script](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/builds/libtensorflow_nightly_symlink.sh)
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

## Setup

### Download and extract

<br />

| TensorFlow C library | URL |
|---|---|
| Linux > [!CAUTION] > **Caution:** TensorFlow 2.16 was the last TensorFlow release that supported macOS x86. > **Caution:** TensorFlow 2.18 was the last release of Linux x86 libtensorflow packages. ||
| Linux CPU only | <https://storage.googleapis.com/tensorflow/versions/2.18.0/libtensorflow-cpu-linux-x86_64.tar.gz> |
| Linux GPU support | <https://storage.googleapis.com/tensorflow/versions/2.18.0/libtensorflow-gpu-linux-x86_64.tar.gz> |
| macOS > [!CAUTION] > **Caution:** TensorFlow 2.16 was the last TensorFlow release that supported macOS x86. > **Caution:** TensorFlow 2.18 was the last release of Mac Arm64 Libtensorflow packages. ||
| macOS CPU only | <https://storage.googleapis.com/tensorflow/versions/2.16.2/libtensorflow-cpu-darwin-x86_64.tar.gz> |
| macOS ARM64 CPU only | <https://storage.googleapis.com/tensorflow/versions/2.18.0/libtensorflow-cpu-darwin-arm64.tar.gz> |
| Windows > [!CAUTION] > **Caution:** TensorFlow 2.10 was the last TensorFlow release that supported GPU on native-Windows. > **Caution:** TensorFlow 2.18 was the last release of Windows x86 libtensorflow packages. ||
| Windows CPU only | <https://storage.googleapis.com/tensorflow/versions/2.18.1/libtensorflow-cpu-windows-x86_64.zip> |
| Windows GPU only | <https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-2.10.0.zip> |

<br />

<br />

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`:

    FILENAME=libtensorflow-cpu-linux-x86_64.tar.gz
    wget -q --no-check-certificate https://storage.googleapis.com/tensorflow/versions/2.18.1/${FILENAME}
    sudo tar -C /usr/local -xzf ${FILENAME}

### Linker

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:

<br />

### Linux

```bash
export LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/mydir/lib
```

### macOS

```bash
export LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:~/mydir/lib
```

<br />

## Build

### 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

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

    gcc hello_tf.c -ltensorflow -o hello_tf

    ./hello_tf

```
Hello from TensorFlow C library version 2.18.1
```

> [!TIP]
> **Success:** The TensorFlow C library is configured.

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_tf

```
Hello from TensorFlow C library version 2.18.1
```

## Build from source

TensorFlow is open source. Read
[the instructions](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/lib_package/README.md)
to build TensorFlow's C library from source code.