Build specific library from Boost C++ Library - c++

I built the boost library in order to use the boost functions split and format.
I noticed that the split placed under the algorithm directory, but there is no library named 'algorithm' when I run --show-libraries to get the list of libraries.
When I built the whole boost, I didn't find which lib file to add to my project (I don't want to add the all the libs and headers).
How can I build this specific library?

Both boost::algorithm and boost::format are header only, so no need to build.
You will find both header files inside the include/boost/ folder:
include/boost/algorithm/algorithm.hpp
include/boost/format.hpp

When running bootstrap with --show-libraries:
The Boost libraries requiring separate building and installation are:
The algorithm library isn't listed and is even template for the STL equivalent -> header-only.

Related

Header only libraries with scons

I am new to scons so maybe my google-fu is really bad but I could not find a way to create a header-only C++ library. I know I can use CPPPATH to put directories in the include path but that is not ideal. My library libonlyheader depends on other external libraries like fmt and boost and I want executables and libraries built with these to transitively depend on fmt and boost as well. Essentially I am looking for a feature like the cmake's INTERFACE libraries.

using shared library with custom file extension with cMake

I working on a C++ application running on Linux. The project uses CMake.
It use a third party shared library. Unfortunately, the third party library doesn't end with .so.
And the CMake command find_library can't find the library.
Does anyone now how to force CMake to find libraries with a custom file extension? Or at least, how to configure GCC (through CMake) for linking with the library ending with a custom extension?
Thanks for any hint!
You can set the CMAKE_FIND_LIBRARY_SUFFIXES variable. From the documentation:
This specifies what suffixes to add to library names when the
find_library() command looks for libraries. On Windows systems this is
typically .lib and .dll, meaning that when trying to find the foo
library it will look for foo.dll etc.
Adding the custom suffix to it should do the trick.

How to build boost log v2 with cmake?

It seems that most users will just use a pre build version of boost in combination with find_package.
I always download my 3rd party dependencies via git and integrate them in cmake. This was usually not a problem because all my libraries were either using cmake or were just header only libraries.
How would I integrate boost log into my cmake build system? Do I need to treat it as if I had written it myself and compile it manually by including every .h and .cpp files and build it as a shared library?
Or is there a more simple way, for example reusing the .jam file in cmake?

How to use external DLLs in CMake project

I've been searching over the internet but I couldn't find anything that would answer my question (or I don't know what to search for).
Anyway here's my issue:
I want to use 3rdParty libraries (.dll files) in my CMake project. Library (https://github.com/pitzer/SiftGPU) that I want to include is open source and is also available in binary which I would like to use and also uses CMake as build tool if that's relevant.
I hope I was clear enough.
First, edit your CMakeLists.txt to include your third party library. You'll need two thing: path to header files and library file to link to. For instance:
# searching for include directory
find_path(SIFTGPU_INCLUDE_DIR siftgpu.h)
# searching for library file
find_library(SIFTGPU_LIBRARY siftgpu)
if (SIFTGPU_INCLUDE_DIR AND SIFTGPU_LIBRARY)
# you may need that if further action in your CMakeLists.txt depends
# on detecting your library
set(SIFTGPU_FOUND TRUE)
# you may need that if you want to conditionally compile some parts
# of your code depending on library availability
add_definitions(-DHAVE_LIBSIFTGPU=1)
# those two, you really need
include_directories(${SIFTGPU_INCLUDE_DIR})
set(YOUR_LIBRARIES ${YOUR_LIBRARIES} ${SIFTGPU_LIBRARY})
endif ()
Next, you can do the same for other libraries and when every libraries are detected, link to the target:
target_link_libraries(yourtarget ${YOUR_LIBRARIES})
Then you can configure your project with CMake, but as it doesn't have any magic way to find your installed library, it won't find anything, but it'll create two cache variables: SIFTGPU_INCLUDE_DIR and SIFTGPU_LIBRARY.
Use the CMake GUI to have SIFTGPU_INCLUDE_DIR pointing to the directory containing the header files and SIFTGPU_LIBRARY to the .lib file of your third party library.
Repeat for every third party library, configure again and compile.

Including my own shared library with cmake

I have the following code in my CMakeLists.txt for finding my shared library libsieve.so
set(CPPLIB_DIR "${CMAKE_SOURCE_DIR}/../core/build")
find_library(CPPLIB_SIEVE_LIBRARY NAMES libsieve PATHS CPPLIB_DIR)
But it fails and won't find my library. I have the following directory structure:
core
build: libsieve.so
project: CMakeLists.txt
What am I doing wrong?
I don't know why cmake doesn't find the needed library but I can suggest a way to make it happen with the help cmake-gui: if the first run of "configure" fails to find the library you can point it to the needed library manually (set the full absolute path). Most of the time such solution works for me.
Also if the library was built with one tool chain (say, Intel C++) and you project is being built with another tool chain (say, clang) the failure to find the library may be due to binary incompatibility between the project and the library.
Upd. The original problem was referencing CPPLIB_DIR. It should have been:
find_library(CPPLIB_SIEVE_LIBRARY NAMES sieve PATHS ${CPPLIB_DIR})
Cmake find_library expect you to provide the library name or the library file name.
You mixed the two by adding a "lib" prefix to your library name. So you should try to replace libsieve by either sieve or libsieve.so.