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.
Related
I want to use specific version of CMake 3.19.0 for Ubuntu 14.04 (32-bits) without installing CMake (use only binaries).
I tried to build CMake 3.19.0 on my test machine. It builded and installed successfully. In install_manifest.txt I see lot of files that were installed on my test system.
So, I tried to copy only installed binaries from /usr/local/bin/ (this is default path where CMake binaries were installed) and paste it to another machine that doesn't know about CMake. I paste 3 binaries: cmake, ctest, cpack to /usr/local/bin/.
If I run which cmake it shows path:
/usr/local/bin/cmake
If I run cmake --verison it shows:
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/local/share/cmake-3.19
cmake version 3.19.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
It looks like CMake needs some modules that I haven't copied yet. I tried to build my cpp project and it shows me:
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/local/share/cmake-3.19
CMake Error: Error executing cmake::LoadCache(). Aborting.
What are the minimum required modules needed for stable building? And where I should copy it?
Just copied builded Modules and Templates directories from cmake-3.19.0 build directory to /usr/local/share/cmake-3.19
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}
I am trying to install the GPU support for XGBoost but I get the following error when I try to build it with CMake:
CMake Error at /usr/local/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find CUDA: Found unsuitable version "7.5", but required is at
least "8.0" (found /usr)
I only installed CUDA 8.0 and the environmental variables in .bashrc are specified as:
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
How can I have CMake detect the right CUDA version?
PATH and LD_LIBRARY_PATH have no effect on cmake, so what you have tried will not work.
If you look at the documentation for find_package it is possible to provide a PATHS argument to tell cmake to look in non-standard locations
Unfortunately, if you look at the source for XGBoost's CMakeLists.txt, you can see it calls find_package(CUDA ...), but doesn't allow the user to provide a PATHS option
if(USE_CUDA)
find_package(CUDA 8.0 REQUIRED)
...
endif()
As such you are left with 2 options:
Edit XGBoost's CMakeLists.txt file, and add PATHS /usr/local/cuda-8.0 to the find_package call
Install cuda-8.0 into a standard location (eg: use /usr/local as your PREFIX, not /usr/local/cuda-8.0)
I ran into a similar issue when trying to install the R version with GPU support. The issue was that I was running the commands from their install guide:
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
git submodule init
git submodule update
cd R-package
R CMD INSTALL .
and then running the commands for GPU support:
mkdir build
cd build
cmake .. -DUSE_CUDA=ON -DR_LIB=ON
I was able to avoid the issue by running:
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
mkdir build
cd build
cmake .. -DUSE_CUDA=ON -DR_LIB=ON
make install -j
I'm on windows, tried to install EASTL, it got installed in Program Files instead of compiler's path.
Maybe I should change something in CMakeLists?
Library's CMakeLists: https://github.com/electronicarts/EASTL/blob/master/CMakeLists.txt
Commands I used:
cmake -G"MSYS Makefiles"
make
make install
It's a little tricky because MSYS2's CMake is a native Windows program that only understands Windows paths, and MSYS2 has automatic conversions of paths from POSIX-style to Windows-style that gets in the way sometimes.
These commands should work:
MSYS2_ARG_CONV_EXCL=- cmake . -G"MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=$MSYSTEM_PREFIX
make install DESTDIR=/
Following the instructions to compile dlib using cmake (here) generates a static dlib library:
cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release
How can I instruct cmake to generate a shared (.so) library instead?
If you want to make a .so file then do this:
cd dclib/dlib
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=1 ..
make
sudo make install
On a unix system, that will install dlib system wide. This means installing the .so file and also the header files so you can compile programs with a command like g++ main.cpp -ldlib. Finally, on linux systems you will also need to run sudo ldconfig after installing any new shared libraries.
However, for most users, I would recommend using CMake as shown in the examples. That way would allow you to enable or disable debugging modes whenever you want and also makes distributing the project easier, both in source form and compiled form. For example, if you wanted to compile on windows then shared libraries are definitely not the way to go. Moreover, using CMake as shown in the examples will always work in a straightforward manner without any setup.
According to dlib/CMakeLists.txt, standalone (not from examples) building of dlib also creates shared library named dlib-shared:
mkdir shared_build # Build directory can be any
cd shared_build
cmake ..
cmake --build . --config Release
make install # Install library for make it acessible for others
For use this library in examples, you need to add definition of dlib library into your examples/CMakeLists.txt before include(../dlib/cmake).
examples/CMakeLists.txt:
...
PROJECT(examples)
add_library(dlib SHARED IMPORTED) # Imported(!) dlib target
set_target_properties(dlib PROPERTIES IMPORTED_LOCATION "<full path to the installed dlib-shared library file>")
# Now it is safe to include other dlib infrustucture - it won't build dlib again.
include(../dlib/cmake)
...