Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the Boost library names for CMake

Tags:

boost

cmake

I am trying to figure out what components to Find in CMakeList.txt for boost libraries.

I looked at this directory /usr/local/include/boost. And I randomly pick some of the folders and try to use FIND_PACKAGE. These following all works well.

FIND_PACKAGE(Boost COMPONENTS thread system log log_setup                     signals graph memory_order program_options REQUIRED) 

The particular one that I am using is property_tree. It is not working and produces the following error message:

CMake Error at /Applications/CMake.app/Contents/share/cmake-3.1/Modules/FindBoost.cmake:1182 (message):

Unable to find the requested Boost libraries.

Boost version: 1.55.0

Boost include path: /usr/local/include

Could not find the following static Boost libraries:

    boost_property_tree 

Could anyone explain how or where I can find the proper library names for boost?

like image 787
Yuchen Avatar asked Nov 05 '14 03:11

Yuchen


People also ask

How do you get a Boost with CMake?

You can use find_package to search for available boost libraries. It defers searching for Boost to FindBoost. cmake, which is default installed with CMake. Upon finding Boost, the find_package() call will have filled many variables (check the reference for FindBoost.

How many libraries Boost?

Boost is a set of libraries for the C++ programming language that provides support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It contains 164 individual libraries (as of version 1.76).


2 Answers

The COMPONENTS part of FIND_PACKAGE only searches for compiled libraries. It is not able to check for the header-only libraries that comprise a major part of Boost. There are only a few libraries that require linking (mostly those that perform platform-specific things).

From your examples, only thread, signals (in contrast to signals2 which is header-only), system and program_options need to be build beforehand and then linked with your program. For the rest, it is sufficient to include the relevant header files .

Thus, it is sufficient to add ${Boost_INCLUDE_DIRS} to the include directories of your target.

See here for a list of libraries of these libraries Which boost libraries are header-only?

like image 69
Johannes S. Avatar answered Sep 21 '22 14:09

Johannes S.


If boost library is compiled, then component name is basically lowercase name of library without prefixes and suffixes (for example for boost_system-vc141-mt-x64-1_66.lib it would be 'system')

Also see here: https://cmake.org/cmake/help/v3.10/module/FindBoost.html

like image 42
Leonid Avatar answered Sep 22 '22 14:09

Leonid