Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to copy Tensorflow headers to build custom C++ applications
#!/bin/bash
# inspired by a part of: https://github.com/cjweeks/tensorflow-cmake/blob/master/build.sh
#
# Assumes Tensorflow libraries libtensorflow_framework.so and libtensorflow_cc.so were built with Bazel,
# and the ${TF_ROOT}/tensorflow/contrib/makefile/download_dependencies.sh script was executed.
set -o nounset
set -o errexit
set -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE_DIR=/home/****/Downloads/tensorflow
INSTALL_DIR=/home/****/Documents/tf_cpp_example/tensorflow
INCLUDE_DIR=${INSTALL_DIR}/include
LIB_DIR=${INSTALL_DIR}/lib
# clean
rm -rf ${INSTALL_DIR}
mkdir -p ${INCLUDE_DIR}
mkdir -p ${LIB_DIR}
# copy the library to the install directory
cp ${SOURCE_DIR}/bazel-bin/tensorflow/libtensorflow_cc.so ${LIB_DIR}/ || exit 0
cp ${SOURCE_DIR}/bazel-bin/tensorflow/libtensorflow_framework.so ${LIB_DIR}/ || exit 0
# Copy the TF includes to $INSTALL_DIR/include/google and remove unneeded items:
mkdir -p ${INCLUDE_DIR}/google/tensorflow
cp -r ${SOURCE_DIR}/tensorflow ${INCLUDE_DIR}/google/tensorflow/
find ${INCLUDE_DIR}/google/tensorflow/tensorflow -type f ! -name "*.h" -delete
# Copy all generated files from bazel-genfiles:
cd ${SOURCE_DIR}/bazel-genfiles/
for f in $(find ${SOURCE_DIR}/ -name "*.h"); do cp --parents $f ${INCLUDE_DIR}/google/tensorflow/; done
cd ${DIR}
# Copy the third party Eigen 3 bindings
mkdir -p ${INCLUDE_DIR}/google/tensorflow/third_party
cp -r ${SOURCE_DIR}/third_party/eigen3 ${INCLUDE_DIR}/google/tensorflow/third_party
# Copy the Eigen 3 implementation
mkdir -p ${INSTALL_DIR}/include/eigen3
cp -r ${SOURCE_DIR}/tensorflow/contrib/makefile/downloads/eigen/Eigen \
${SOURCE_DIR}/tensorflow/contrib/makefile/downloads/eigen/unsupported \
${INCLUDE_DIR}/eigen3
# Copy protobuf includes
cp -r ${SOURCE_DIR}/tensorflow/contrib/makefile/downloads/protobuf/build/include/* ${INCLUDE_DIR}/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.