I've been through the steps to build tensorflow and it's working in python. Now how do I BUILD the C tensorflow library I want to use?
$ gcc -I../tensorflow -ltensorflow g.c
/usr/bin/ld: cannot find -ltensorflow
collect2: error: ld returned 1 exit status
To build the C library from source, follow most of the instructions for building TensorFlow from source, except that instead of building the pip package, build the tarball that packages the shared libraries and C API header file:
bazel build -c opt //tensorflow/tools/lib_package:libtensorflow
This will produce a tarball in:
bazel-bin/tensorflow/tensorflow/tools/lib_package/libtensorflow.tar.gz
More details in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/lib_package/README.md
The release binaries are built using the process described above.
Hope that helps.
There are 2 libraries you have to build:
libtensorflow_framework.so
libtensorflow.so
To build them you have to use bazel
bazel build //tensorflow:libtensorflow_framework.so
bazel build //tensorflow:libtensorflow.so
Once the build process of both libraries ends, you have to make the linker aware of where these libraries are, hence you have to upgrade the LIBRARY_PATH and the LD_LIBRARY_PATH accordingly.
TENSORFLOW_LIB = "/path/of/tensorflow/bazel-bin/tensorflow/"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${TENSORFLOW_LIB}`
export LIBRARY_PATH=${LIBRARY_PATH}:${TENSORFLOW_LIB}
Related
I'd like to build the TensorFlow Lite as C API static library (Linux Debian x64). The instructions state the following CMake workflow:
// get the sources
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
// create a build directory
mkdir tflite_build
cd tflite_build
// build the lib using CMake
cmake ../tensorflow_src/tensorflow/lite/c
cmake --build . -j
However, this builds the shared library libtensorflowlite_c.so.
What would be the recommended way to build static version of the C API lib? Does modifying the CMake config files require expert CMake knowledge or it could be achieved rather easy?
According to the TensorFlow Lite CMakeLists.txt file this should be rather easy. Add -DTFLITE_C_BUILD_SHARED_LIBS:BOOL=OFF to your CMake configuration step. That means, clear your build directory before doing any changes and rerun the CMake commands
cmake -S ../tensorflow_src/tensorflow/lite/c -DTFLITE_C_BUILD_SHARED_LIBS:BOOL=OFF
cmake --build . -j
Be sure to also add to your project a dependency to TF-lite and its dependencies (as mentioned here in its CMakeLists.txt) if they are not header only, as TF-lite does not provide a CMake config package (AFAIK) that otherwise would include these transitive dependencies.
I'm trying compiling Tensorflow 1.15 on Odroid-XU4 and getted some error that seems not related and exclusive to my platform. I installed Tensorflow 1.13 by source compile successfully. But for TF1.15 I got some error which experienced when use TF1.15.0 and TF1.15.1 and TF1.15.3.
My command to build using Bazel 0.26.1 is:
bazel --output_base=/media/odroid/.../CacheFolder build --config=opt --config=monolithic --config=noaws --jobs 1 --define=grpc_no_ares=true --local_resources 1536,0.5,1.0 tensorflow:libtensorflow_cc.so --discard_analysis_cache
After getting error for package "#io_rules_docker" which fixed by adding manually in WORKSPACEFILE and some same error I got this error:
>no such package '#highwayhash//': BUILD file not found on package path and referenced by '//tensorflow/core/platform/default/build_config:platformlib'
How can I solve this?
I need to run tests on some XLA passes and used bazel test
--config=opt --config=cuda //tensorflow/compiler/xla/service to do the same (from here). The build failed with the following message, hinting at the missing googletest dependency.
/usr/lib/x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
The dependences libgtest.a and libgtest_main.a were built from the googletest source and passed to the linker using --linkopt=/path/to/file.
googletest/googletest/libgtest_main.a(gtest_main.cc.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
Adding -DCMAKE_CXX_FLAGS=-fPIC didn't help. How can I change the cmake config to build with -fPIC ?
tensorflow (v1.8) is configured to be built by a locally built version gcc (5.4), since the system's version (5.5) fails to build tensorflow. Would that be the cause of the problem ?
Linking to the shared libraries instead of the object file archive solved this problem, i.e.,
bazel test --linkopt="$GTEST_DIR/libgtest.so" --linkopt="GTEST_DIR/libgtest_main.so"
instead of,
bazel test --linkopt="$GTEST_DIR/libgtest.a" --linkopt="GTEST_DIR/libgtest_main.a"
This still doesn't help run tensorflow unit tests. There are build errors in dependences of the unit tests, eg. the compilation of //tensorflow/...../absl/base/internal fails.
So, I've installed Bazel via Chocolatey, installed Python 3.5 and 2.7, installed CUDA v8, and cuDNN v6, and installed JDK 8.0, I'm now trying to custom-build TensorFlow on my Windows 10 device, with AVX, AVX 2 and CUDA. TensorFlow-GPU, the pre-built version, does work, I've already tested and run that successfully.
I've followed the instructions of other articles, both on TensorFlows' actual site (trying to adapt some sections from the Linux/Mac installs), and on here. The furthest I've made it is; cloning the Github repository via Msys2, running configure.py, then attempting to build via bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package I receive an error, the header of which is:
Error reading java.io.IOException: CreateProcess(): The system cannot find the file specified.
: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/include/cudnn.h
I've double checked, that file does exist, so I'm not sure why I'm getting this error.
EDIT: Also attempted to run via Powershell, reached the same point.
Any help would be much appreciated.
I had the exact same error while trying to build Tensorflow on Windows (using cuDNN 5.1). I fixed it by launching bazel from the msys2 terminal (instead of from the windows command prompt) and manually setting the BAZEL_SH environment variable before attempting to build.
export BAZEL_SH=c:/tools/msys64/usr/bin/bash.exe
bazel build -c opt --config=win-cuda tensorflow/cc:cc_ops
The following steps helped me to compile Tensorflow on Windows 10.
pacman -Syuu patch
ln -s "c:\python27\python.exe" /usr/bin/python
export BAZEL_SH=c:/tools/msys64/usr/bin/bash.exe
"C:\Documents and Settings\All Users\chocolatey\bin\bazel.exe" build --config=opt --config=win-cuda //tensorflow/tools/pip_package:build_pip_package
But after 1 hour of compilation I got another error:
C:\tools\msys64\tmp_bazel_dmitry\x1e5egqw\execroot\org_tensorflow\external\protobuf_archive\python\google\protobuf\internal\api_implementation.cc
: fatal error C1083: Cannot open compiler generated file: '': Invalid
argument Target //tensorflow/tools/pip_package:build_pip_package
failed to build
I am getting a build error when executing TF.
I have an include file issue. I have installed latest zlib1g-dev, but no luck.
Bazel binaries built from source V0.3.2,
TF command:
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
ERROR:
ERROR: tensorflow/core/BUILD:853:1: undeclared inclusion(s) in rule '//tensorflow/core:lib_internal':
this rule is missing dependency declarations for the following files included by 'tensorflow/core/lib/png/png_io.cc':
~/.cache/bazel/_bazel_madhu/a9aabe45cf3d94341ef4fb777deb58c5/external/zlib_archive/zlib.h'
~/.cache/bazel/_bazel_madhu/a9aabe45cf3d94341ef4fb777deb58c5/external/zlib_archive/zconf.h'."
Clean your $HOME/.cache/bazel directory.