If you compile for host linux, make sure you have cmake (version >= 3.10.2), gcc (version >= 6.3). If you also compile for arm, make sure your toolchain's attribute CMAKE_SYSTEM_PROCESSOR contains "arm", "Arm", or "ARM", as I use this attribute to detect cross-compiling. It's been tested for linux host, armv8-a.
cd tensorflow/contrib/cmake
mkdir x86 # if you also want to cross-compile later, do NOT change the directory name.
cd x86
cmake .. -DCMAKE_BUILD_TYPE=Release -Dtensorflow_BUILD_PYTHON_BINDINGS=OFF -Dtensorflow_BUILD_SHARED_LIB=ON
make -j$(nproc)
The output is in the directory "x86". The shared library is libtensorflow.so. The protoc tool sits in the sub-folder "protobuf/src/protobuf". If you want to use the C++ api, you need to run several times of protoc commands to generate source files. The following cross-compiling process will also invoke this command to generate source files.
Make sure you have finished the last step and have the compiled results in the directory "x86".
cd tensorflow/contrib/cmake
mkdir arm
cd arm
cmake .. -DCMAKE_BUILD_TYPE=Release -Dtensorflow_BUILD_PYTHON_BINDINGS=OFF -Dtensorflow_BUILD_SHARED_LIB=ON -DCMAKE_TOOLCHAIN_FILE=<YOU TOOLCHAIN FILE>
make -j$(nproc)
For both of the above cmake commands, you may also pass in "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF", if you don't need it in your library.
- changed the executable programs for cross-compling.
- added "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" for third-party dependences that use cmake to build.
- added "--host=aarch64-linux-gnu" for third-party dependences that use autoconfig/make to build.
- changed the urls of the some third-party dependences to the ones bazel currently uses for building tensorflow.
- make a minimum runtime library for inference.