[null,null,["上次更新時間:2021-09-21 (世界標準時間)。"],[],[],null,["# Install TensorFlow for C\n\n|---------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|\n| [View on TensorFlow.org](https://www.tensorflow.org/install/lang_c) | [Run in Google Colab](https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/install/lang_c.ipynb) | [View source on GitHub](https://github.com/tensorflow/docs/blob/master/site/en/install/lang_c.ipynb) | [Download notebook](https://storage.googleapis.com/tensorflow_docs/docs/site/en/install/lang_c.ipynb) |\n\nTensorFlow provides a C API that can be used to build\n[bindings for other languages](https://github.com/tensorflow/docs/tree/master/site/en/r1/guide/extend/bindings.md).\nThe API is defined in\n[`c_api.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/c/c_api.h)\nand designed for simplicity and uniformity rather than convenience.\n\nNightly libtensorflow C packages\n--------------------------------\n\nlibtensorflow packages are built nightly and uploaded to GCS for all supported\nplatforms. They are uploaded to the\n[libtensorflow-nightly GCS bucket](https://storage.googleapis.com/libtensorflow-nightly)\nand are indexed by operating system and date built. For MacOS and Linux shared\nobjects, there is a\n[script](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/builds/libtensorflow_nightly_symlink.sh)\nthat renames the `.so` files versioned to the current date copied into the\ndirectory with the artifacts.\n\nSupported Platforms\n-------------------\n\nTensorFlow for C is supported on the following systems:\n\n- Linux, 64-bit, x86\n- macOS, Version 10.12.6 (Sierra) or higher\n- Windows, 64-bit x86\n\nSetup\n-----\n\n### Download and extract\n\n\u003cbr /\u003e\n\n| TensorFlow C library | URL |\n|----------------------|-------------------------------------------------------------------------------------------------------|\n| Linux | **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. ||\n| Linux CPU only | \u003chttps://storage.googleapis.com/tensorflow/versions/2.18.0/libtensorflow-cpu-linux-x86_64.tar.gz\u003e |\n| Linux GPU support | \u003chttps://storage.googleapis.com/tensorflow/versions/2.18.0/libtensorflow-gpu-linux-x86_64.tar.gz\u003e |\n| macOS | **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. ||\n| macOS CPU only | \u003chttps://storage.googleapis.com/tensorflow/versions/2.16.2/libtensorflow-cpu-darwin-x86_64.tar.gz\u003e |\n| macOS ARM64 CPU only | \u003chttps://storage.googleapis.com/tensorflow/versions/2.18.0/libtensorflow-cpu-darwin-arm64.tar.gz\u003e |\n| Windows | **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. ||\n| Windows CPU only | \u003chttps://storage.googleapis.com/tensorflow/versions/2.18.1/libtensorflow-cpu-windows-x86_64.zip\u003e |\n| Windows GPU only | \u003chttps://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-2.10.0.zip\u003e |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nExtract the downloaded archive, which contains the header files to include in\nyour C program and the shared libraries to link against.\n\nOn Linux and macOS, you may want to extract to `/usr/local/lib`: \n\n FILENAME=libtensorflow-cpu-linux-x86_64.tar.gz\n wget -q --no-check-certificate https://storage.googleapis.com/tensorflow/versions/2.18.1/${FILENAME}\n sudo tar -C /usr/local -xzf ${FILENAME}\n\n### Linker\n\nOn Linux/macOS, if you extract the TensorFlow C library to a system directory,\nsuch as `/usr/local`, configure the linker with `ldconfig`: \n\n sudo ldconfig /usr/local/lib\n\nIf you extract the TensorFlow C library to a non-system directory, such as\n`~/mydir`, then configure the linker environmental variables:\n\n\u003cbr /\u003e\n\n### Linux\n\n```bash\nexport LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib\nexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/mydir/lib\n```\n\n### macOS\n\n```bash\nexport LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib\nexport DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:~/mydir/lib\n```\n\n\u003cbr /\u003e\n\nBuild\n-----\n\n### Example program\n\nWith the TensorFlow C library installed, create an example program with the\nfollowing source code (`hello_tf.c`): \n\n %%writefile hello_tf.c\n #include \u003cstdio.h\u003e\n #include \u003ctensorflow/c/c_api.h\u003e\n\n int main() {\n printf(\"Hello from TensorFlow C library version %s\\n\", TF_Version());\n return 0;\n }\n\n```\nWriting hello_tf.c\n```\n\n### Compile\n\nCompile the example program to create an executable, then run: \n\n gcc hello_tf.c -ltensorflow -o hello_tf\n\n ./hello_tf\n\n```\nHello from TensorFlow C library version 2.18.1\n```\n| **Success:** The TensorFlow C library is configured.\n\nIf the program doesn't build, make sure that `gcc` can access the TensorFlow C\nlibrary. If extracted to `/usr/local`, explicitly pass the library location to\nthe compiler: \n\n gcc -I/usr/local/include -L/usr/local/lib hello_tf.c -ltensorflow -o hello_tf\n\n ./hello_tf\n\n```\nHello from TensorFlow C library version 2.18.1\n```\n\nBuild from source\n-----------------\n\nTensorFlow is open source. Read\n[the instructions](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/lib_package/README.md)\nto build TensorFlow's C library from source code."]]