Using libtensorflow_cc.so in an existing C++ cmake project - c++

I have an existing C++ cmake project and I want to use tensorflow in it as a third party library. I searched extensively but all the solutions involve installing tensorflow at the end or copying the files to /usr/local directory.
My problem is I don't want to make any changes to the system directories and everything should happen within my project directory.
So, I compiled libtensorflow_cc.so and libtensorflow_framework.so from tensorflow source code and copied into my project directory. I added below code in my CMake to link these libraries.
find_library(tensorflowlibfwk libtensorflow_framework.so
PATHS ${PROJECT_SOURCE_DIR}/thirdparty/lib)
find_library(tensorflowlibcc libtensorflow_cc.so
PATHS ${PROJECT_SOURCE_DIR}/thirdparty/lib)
target_link_libraries(tensorflowtest ${tensorflowlibfwk} ${tensorflowlibcc})
I have no idea about which headers should I include to use the tensorflow in my project ??
Any kind of help please

Related

Linking to Tensorflow as an external lib to C++ application

Are there any supported alternatives to the approach presented on the Tensorflow C++ guide that instead allows you to separately build Tensorflow and link your C++ application to it as an external library?
I've managed to compile libtensorflow_cc.so and link to it. But where can I get valid header-files. Just grabbing the header-files from source gives errors and I have to manually adjust the paths, which I'd rather avoid.
I use this https://github.com/FloopCZ/tensorflow_cc repository and add find_package(TensorflowCC REQUIRED) in cmake and there is no issue with include file and not with lib target_link_libraries(project_name TensorflowCC::Shared)
or check that you include file path is correct to the path to you TF installation

I used bazel to build a shared library. But, how to automatically install all headers in specific directory

I'm a newbie to bazel. I build a lib from tensorflow source. But How to automatically generate include directory, including all headers. Thank Thank you! !
now I got a libxxx.so(using tensorflow/core/so_many_header.h) from bazel build. I need some include files, when using libxxx.so. But where are headers files?.

Embedding library and it's includes via CMake

I'm creating a very small project that depends on the following library: https://github.com/CopernicaMarketingSoftware/AMQP-CPP
I'm doing what i always do with third-party libraries: i add their git repo as a submodule, and build them along with my code:
option(COOL_LIBRARY_OPTION ON)
add_subdirectory(deps/cool-library)
include_directories(deps/cool-library/include)
target_link_libraries(${PROJECT_NAME} coollib)
This has worked perfectly for libraries like Bullet, GLFW and others. However, this AMQP library does quite an ugly hack. Their include directory is called include, but in their CMake install() command, they rename it to amqpcpp. And their main header, deps/cool-library/amqpcpp.h, is referencing all other headers using that "fake" directory.
What happens is: when CMake tries to compile my sources which depend on deps/cool-library/amqpcpp.h, it fails because it's not finding deps/cool-library/amqpcpp/*.h, only deps/cool-library/include.
Does anyone have any idea how i can fix this without having to bundle the library into my codebase?
This is not how CMake is supposed to work.
CMake usually builds an entire distributive package of a library once and then installs it to some prefix path. It is then accessible for every other build process on the system by saying "find_package()". This command finds the installed distibution, and all the libs, includes etc. automagically. Whatever weird stuff library implementers did, the resulting distros are more or less alike.
So, in this case you do a lot of unnecessary work by adding includes manually. As you see it can also be unreliable.
What you can do is:
to still have all the dependencies source distributions in submodules (usually people don't bother doing this though)
build and install each dependency package into another (.gitignored) folder within the project or outside by using their own CMakeLists.txt. Let's say with a custom build step in your CMakeLists.txt
use "find_package()" in your CMakeLists.txt when build your application
Two small addition to Drop's answer: If the library set up their install routines correctly, you can use find_package directly on the library's binary tree, skipping the install step. This is mostly useful when you make changes to both the library and the dependent project, as you don't have to run the INSTALL target everytime to make library changes available downstream.
Also, check out the ExternalProject module of CMake which is very convenient for having external dependencies being built automatically as part of your project. The general idea is that you still pull in the library's source as a submodule, but instead of using add_subdirectory to pull the source into your project, you use ExternalProject_Add to build it on its own and then just link against it from your project.

How to correctly include Dlib in Eclipse project?

I'm currently trying to use the Dlib c++ library in my own project. So I included the main folder of dlib to my project. I also added the dlib/all/source.cpp to my project. When I try to compile the code of the svm_c_ex.cpp example in my own test.cpp file, I only get:
fatal error: dlib/svm.h: No such file or directory
The section Dlib: How to compile didn't help me and I couldn't find further information online. Any help is appreciated!
You need to compile the DLib library first, using the instructions from the website.
cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake is a famous tool to build software on multiple platforms. It generates required files first and then you can compile the library using those generated files later.
You need to add the "include" directories (the folders where the headers exist) in your project configuration. I'm quite not sure of where exactly to add in Eclipse CDT.
After that, your program gives linker error because the the header files only contain skeletons of your library code. Actual implementation need to be linked with "linker options" in project properties. You need to add your library's .lib/.a files with your program. I don't exactly remember where is linker options in CDT (I'm talking in Visual Studio context)
Basically for any library you want to use in any C++ project:
You need to include HEADERS in your project properties
You need to link to actual implementation of the library. You can read about
static and dynamic libraries (Someone on SO must have given an
awesome explanation)

Integrate ITK (Insight Toolkit) into own project

i am having problems integrating ITK - Insight Toolkit into another image processing pipeline. ITK itself is a medical image processing toolkit and uses cmake as build system. My image pipeline project uses cmake as well. According to the user manual of ITK it is favorable to use the "UseITK.cmake" file in the build (out of source) directory of ITK. You can do that by adding the following lines the CMakeList.txt of your own project.
# 'SET(ITK_DIR ...)' if 'FIND_PACKAGE(ITK REQUIRED)' fails
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
My problem is, this approach points to the current installtion of ITK, but i have to integrate itk completly into my project, without dependencies outside my project.
Is there a build option in the cmake build system of itk, which dumps/delivers all the header and lib files into a build directory, so i can place them into my project on my own.
I have a lib and header include structure i do not want to break. I already tried to to manually copy the lib and header files into my project but it didn't work out.
I am new to itk and cmake so this question might sound vague. I hope you guys can help me anyway.
Thanks in advance!
Best regards,
zhengtonic
I don't know if you're still having the problem, but here's an easy way:
Build the ITK project, and then "make install" (or build the INSTALL.vcproj project in VS), and it will write to a directory you pass as CMAKE_INSTALL_PREFIX while configuring your project. This directory will contain /bin, /lib and /include. You can import those into your project directly.
Using CMAKE_INSTALL_PREFIX to point to you base directory is the best solution.
When you issue "make install" all the headers/configurationfiles/libraries will be copied over.
C:/Program Files (x86)/ITK is value of CMAKE_INSTALL_PREFIX for ITK and set automatically.