set(boost_use_static_libs on)

  • CMake »
  • 3.27.4 Documentation »
  • cmake-modules(7) »

FindBoost ¶

Find Boost include dirs and libraries

Use this module by invoking find_package() with the form:

This module finds headers and requested component libraries OR a CMake package configuration file provided by a "Boost CMake" build. For the latter case skip to the Boost CMake section below.

New in version 3.7: bzip2 and zlib components (Windows only).

New in version 3.11: The OPTIONAL_COMPONENTS option.

New in version 3.13: stacktrace_* components.

New in version 3.19: bzip2 and zlib components on all platforms.

Result Variables ¶

This module defines the following variables:

True if headers and requested libraries were found.

Boost include directories.

Link directories for Boost libraries.

Boost component libraries to be linked.

True if component <COMPONENT> was found ( <COMPONENT> name is upper-case).

Libraries to link for component <COMPONENT> (may include target_link_libraries() debug/optimized keywords).

BOOST_VERSION value from boost/version.hpp .

Boost version number in X.Y.Z format.

Boost version number in X.Y.Z format (same as Boost_VERSION_STRING ).

Changed in version 3.15: In previous CMake versions, this variable used the raw version string from the Boost header (same as Boost_VERSION_MACRO ). See policy CMP0093 .

Version string appended to library filenames.

Boost major version number ( X in X.Y.Z ).

Boost minor version number ( Y in X.Y.Z ).

Boost subminor version number ( Z in X.Y.Z ).

Amount of version components (3).

Pass to add_definitions() to have diagnostic information about Boost's automatic linking displayed during compilation

New in version 3.15: The Boost_VERSION_<PART> variables.

Cache variables ¶

Search results are saved persistently in CMake cache entries:

Directory containing Boost headers.

Directory containing release Boost libraries.

Directory containing debug Boost libraries.

Component <COMPONENT> library debug variant.

Component <COMPONENT> library release variant.

New in version 3.3: Per-configuration variables Boost_LIBRARY_DIR_RELEASE and Boost_LIBRARY_DIR_DEBUG .

This module reads hints about search locations from variables:

Preferred installation prefix.

Preferred include directory e.g. <prefix>/include .

Preferred library directory e.g. <prefix>/lib .

Set to ON to disable searching in locations not specified by these hint variables. Default is OFF .

List of Boost versions not known to this module. (Boost install locations may contain the version).

Users may set these hints or results as CACHE entries. Projects should not read these entries directly but instead use the above result variables. Note that some hint names start in upper-case BOOST . One may specify these as environment variables if they are not specified as CMake variables or cache entries.

This module first searches for the Boost header files using the above hint variables (excluding BOOST_LIBRARYDIR ) and saves the result in Boost_INCLUDE_DIR . Then it searches for requested component libraries using the above hints (excluding BOOST_INCLUDEDIR and Boost_ADDITIONAL_VERSIONS ), "lib" directories near Boost_INCLUDE_DIR , and the library name configuration settings below. It saves the library directories in Boost_LIBRARY_DIR_DEBUG and Boost_LIBRARY_DIR_RELEASE and individual library locations in Boost_<COMPONENT>_LIBRARY_DEBUG and Boost_<COMPONENT>_LIBRARY_RELEASE . When one changes settings used by previous searches in the same build tree (excluding environment variables) this module discards previous search results affected by the changes and searches again.

Imported Targets ¶

New in version 3.5.

This module defines the following IMPORTED targets:

Target for header-only dependencies. (Boost include directory).

New in version 3.15: Alias for Boost::boost .

Target for specific component dependency (shared or static library); <component> name is lower-case.

Interface target to enable diagnostic information about Boost's automatic linking during compilation (adds -DBOOST_LIB_DIAGNOSTIC ).

Interface target to disable automatic linking with MSVC (adds -DBOOST_ALL_NO_LIB ).

Interface target to enable dynamic linking with MSVC (adds -DBOOST_ALL_DYN_LINK ).

Implicit dependencies such as Boost::filesystem requiring Boost::system will be automatically detected and satisfied, even if system is not specified when using find_package() and if Boost::system is not added to target_link_libraries() . If using Boost::thread , then Threads::Threads will also be added automatically.

It is important to note that the imported targets behave differently than variables created by this module: multiple calls to find_package(Boost) in the same directory or sub-directories with different options (e.g. static or shared) will not override the values of the targets created by the first call.

Other Variables ¶

Boost libraries come in many variants encoded in their file name. Users or projects may tell this module which variant to find by setting variables:

New in version 3.10.

Set to ON or OFF to specify whether to search and use the debug libraries. Default is ON .

Set to ON or OFF to specify whether to search and use the release libraries. Default is ON .

Set to OFF to use the non-multithreaded libraries ("mt" tag). Default is ON .

Set to ON to force the use of the static libraries. Default is OFF .

Set to ON or OFF to specify whether to use libraries linked statically to the C++ runtime ("s" tag). Default is platform dependent.

Set to ON or OFF to specify whether to use libraries linked to the MS debug C++ runtime ("g" tag). Default is ON .

Set to ON to use libraries compiled with a debug Python build ("y" tag). Default is OFF .

Set to ON to use libraries compiled with STLPort ("p" tag). Default is OFF .

Set to ON to use libraries compiled with STLPort deprecated "native iostreams" ("n" tag). Default is OFF .

Set to the compiler-specific library suffix (e.g. -gcc43 ). Default is auto-computed for the C++ compiler in use.

Changed in version 3.9: A list may be used if multiple compatible suffixes should be tested for, in decreasing order of preference.

New in version 3.18.

Set to the platform-specific library name prefix (e.g. lib ) used by Boost static libs. This is needed only on platforms where CMake does not know the prefix by default.

New in version 3.13.

Set to the architecture-specific library suffix (e.g. -x64 ). Default is auto-computed for the C++ compiler in use.

Suffix for thread component library name, such as pthread or win32 . Names with and without this suffix will both be tried.

Alternate namespace used to build boost with e.g. if set to myboost , will search for myboost_thread instead of boost_thread .

Other variables one may set to control this module are:

Set to ON to enable debug output from FindBoost . Please enable this before filing any bug report.

Set to ON to resolve symlinks for discovered libraries to assist with packaging. For example, the "system" component library may be resolved to /usr/lib/libboost_system.so.1.67.0 instead of /usr/lib/libboost_system.so . This does not affect linking and should not be enabled unless the user needs this information.

Default value for Boost_LIBRARY_DIR_RELEASE and Boost_LIBRARY_DIR_DEBUG .

New in version 3.20.

Set to ON to suppress the warning about unknown dependencies for new Boost versions.

On Visual Studio and Borland compilers Boost headers request automatic linking to corresponding libraries. This requires matching libraries to be linked explicitly or available in the link library search path. In this case setting Boost_USE_STATIC_LIBS to OFF may not achieve dynamic linking. Boost automatic linking typically requests static libraries with a few exceptions (such as Boost.Python ). Use:

to ask Boost to report information about automatic linking requests.

Find Boost headers only:

Find Boost libraries and use imported targets:

Find Boost Python 3.6 libraries and use imported targets:

Find Boost headers and some static (release only) libraries:

Boost CMake ¶

If Boost was built using the boost-cmake project or from Boost 1.70.0 on it provides a package configuration file for use with find_package's config mode. This module looks for the package configuration file called BoostConfig.cmake or boost-config.cmake and stores the result in CACHE entry Boost_DIR . If found, the package configuration file is loaded and this module returns with no further action. See documentation of the Boost CMake package configuration for details on what it provides.

Set Boost_NO_BOOST_CMAKE to ON , to disable the search for boost-cmake.

Table of Contents

  • Result Variables
  • Cache variables
  • Imported Targets
  • Other Variables
  • Boost CMake

Previous topic

  • Show Source

Quick search

  • Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • Labs The future of collective knowledge sharing
  • About the company

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Link the static versions of the Boost libraries using CMake

I've got both the static and the dynamic versions of the boost libraries in /usr/lib. Now I'd like CMake to prefer the static versions during the linkage of my executable. What can I do?

cmh's user avatar

2 Answers 2

In your CMakeLists.txt file:

Where I have ... , you optionally put the names of the libraries you want to use, and then target_link_libraries(targetname ${Boost_LIBRARIES}) later below. If you have a fairly recent distribution of CMake, it should work exactly as advertised. I do it exactly this way in my own projects.

Kevin's user avatar

Here is a full example of CMAKEFILE,For example, include boost program options

references:

cmake documents about BOOST

bowman han's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct .

Not the answer you're looking for? Browse other questions tagged c++ boost cmake or ask your own question .

  • The Overflow Blog
  • If you want to address tech debt, quantify it first
  • Fighting comment spam at Facebook scale (Ep. 602)
  • Featured on Meta
  • Moderation strike: Results of negotiations
  • Our Design Vision for Stack Overflow and the Stack Exchange network
  • Call for volunteer reviewers for an updated search experience: OverflowAI Search
  • Discussions experiment launching on NLP Collective
  • Temporary policy: Generative AI (e.g., ChatGPT) is banned

Hot Network Questions

  • Question about klala in parshas Ki Tavo
  • Migrating Windows to a new internal drive, changing drive letters?
  • How did Catwoman manage to pierce Batman's armor using a sewing claw?
  • How to reduce an LP problem already in its standard form?
  • Looking for a series of books that starts with a girl looking in her fridge, realizing she doesn’t like what’s in there and switches it
  • Isn't strong ignorability an incorrect assumption in complex causal structures?
  • Is this outlet safely grounded?
  • sed: deleting the last line (of the input) stops my script
  • Do vampires gain exhaustion during a chase?
  • Is it safe to create a public ID by hashing a private key?
  • What - - - - - - - corresponds to the question mark?
  • Is "abreast a" something ever correct?
  • How do I cite development version of a software?
  • How can I find all integer numbers so that mydistance is an integer number?
  • Is it a canonical elementary CA rule number?
  • "Just" at the end of a question tag
  • Noisy bottom bracket SHIMANO BB-RS500
  • Drawing Asteroids DVG vector objects
  • Do Catholic priests need permission from a bishop to retire?
  • What makes a good alternative to flipping a coin for 50/50 randomness?
  • Uploading a Library to the library manager from a Github branch
  • Why is there a voltage difference between these two grounds?
  • I've always learned that data standardization is not necessary for OLS regression, but then recommended for neural networks. Intuitively, why is that?
  • Is declining an offer to give a talk at a conference halfway around the world a bad idea?

set(boost_use_static_libs on)

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Boost library

The Boost library is included in the find packages that CMake provides, but it has a couple of oddities in how it works. See FindBoost for a full description; this will just give a quick overview and provide a recipe. Be sure to check the page for the minimum required version of CMake you are using and see what options you have.

First, you can customize the behavior of the Boost libraries selected using a set of variables that you set before searching for Boost. There are a growing number of settings, but here are the three most common ones:

In CMake 3.5, imported targets were added. These targets handle dependencies for you as well, so they are a very nice way to add Boost libraries. However, CMake has the dependency information baked into it for all known versions of Boost, so CMake must be newer than Boost for these to work. In a recent merge request , CMake started assuming that the dependencies hold from the last version it knows about, and will use that (along with giving a warning). This functionality was backported into CMake 3.9.

The import targets are in the Boost:: namespace. Boost::boost is the header only part. The other compiled libraries are available, and include dependencies as needed.

Here is an example for using the Boost::filesystem library:

results matching " "

No results matching " ".

Prev

Static and shared libaries

Libraries can be either static , which means they are included in executable files that use them, or shared (a.k.a. dynamic ), which are only referred to from executables, and must be available at run time. Boost.Build can create and use both kinds.

The kind of library produced from a lib target is determined by the value of the link feature. Default value is shared , and to build a static library, the value should be static . You can request a static build either on the command line:

or in the library's requirements:

We can also use the <link> property to express linking requirements on a per-target basis. For example, if a particular executable can be correctly built only with the static version of a library, we can qualify the executable's target reference to the library as follows:

No matter what arguments are specified on the b2 command line, important will only be linked with the static version of helpers .

Specifying properties in target references is especially useful if you use a library defined in some other project (one you can't change) but you still want static (or dynamic) linking to that library in all cases. If that library is used by many targets, you could use target references everywhere:

but that's far from being convenient. A better approach is to introduce a level of indirection. Create a local alias target that refers to the static (or dynamic) version of foo :

The alias rule is specifically used to rename a reference to a target and possibly change the properties.

When one library uses another, you put the second library in the source list of the first. For example:

This works no matter what kind of linking is used. When core is built as a shared library, it is linked directly into utils . Static libraries can't link to other libraries, so when core is built as a static library, its dependency on utils is passed along to core 's dependents, causing app to be linked with both core and utils .

(Note for non-UNIX system). Typically, shared libraries must be installed to a directory in the dynamic linker's search path. Otherwise, applications that use shared libraries can't be started. On Windows, the dynamic linker's search path is given by the PATH environment variable. This restriction is lifted when you use Boost.Build testing facilities—the PATH variable will be automatically adjusted before running the executable.

Copyright 2006, 2014 Vladimir Prus . Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt )

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclusion of static libs for static runtime usage #8

@mellery451

mellery451 commented May 22, 2019

@pdimov

pdimov commented May 22, 2019

Sorry, something went wrong.

@Flamefire

Flamefire commented Jun 7, 2019

No branches or pull requests

@Flamefire

IMAGES

  1. [Solved] Link the static versions of the Boost libraries

    set(boost_use_static_libs on)

  2. C++

    set(boost_use_static_libs on)

  3. OSVR-Core编译_Helen的博客 VR开发者交流群:538874606-CSDN博客

    set(boost_use_static_libs on)

  4. How do I link to Boost statically on Windows? · Issue #16049

    set(boost_use_static_libs on)

  5. How do I link to Boost statically on Windows? · Issue #16049

    set(boost_use_static_libs on)

  6. How do I link to Boost statically on Windows? · Issue #16049

    set(boost_use_static_libs on)

VIDEO

  1. Voltage boost use DC motor 3.7v to 10v

  2. why use static variables in java

  3. What is Enable Power Boost & Use This Feature in Tecno Mobile

  4. POV: you use static electricity feat@icykamman #gorillatag #oculusquest #lightning #thunder

  5. use static electricity Attract on water 💦 ll fun #shorts #viral

  6. Adidas Yeezy Boost 350 V2 Static (Non-Reflective) 2023

COMMENTS

  1. FindBoost

    Boost_USE_STATIC_LIBS. Set to ON to force the use of the static libraries. Default is OFF. Boost_USE_STATIC_RUNTIME. Set to ON or OFF to specify whether to use libraries linked statically to the C++ runtime ("s" tag). Default is platform dependent. Boost_USE_DEBUG_RUNTIME. Set to ON or OFF to specify

  2. Link the static versions of the Boost libraries using CMake

    2 Answers. set (Boost_USE_STATIC_LIBS ON) find_package (Boost REQUIRED ...) Where I have ..., you optionally put the names of the libraries you want to use, and then target_link_libraries (targetname $ {Boost_LIBRARIES}) later below. If you have a fairly recent distribution of CMake, it should work exactly as advertised.

  3. Boost · Modern CMake

    First, you can customize the behavior of the Boost libraries selected using a set of variables that you set before searching for Boost. There are a growing number of settings, but here are the three most common ones: set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF)

  4. Static and shared libaries

    Libraries can be either static, which means they are included in executable files that use them, or shared (a.k.a. dynamic ), which are only referred to from executables, and must be available at run time. Boost.Build can create and use both kinds. The kind of library produced from a lib target is determined by the value of the link feature.

  5. Exclusion of static libs for static runtime usage #8

    # Example to find Boost headers and some *static* libraries:: # # set(Boost_USE_STATIC_LIBS ON) # only find static libs # set(Boost_USE_MULTITHREADED ON) # set(Boost_USE_STATIC_RUNTIME OFF) https://gitlab.kitware.com/cmake/cmake/blob/v3.8.0/Modules/FindBoost.cmake#L1315 (hard coded suffix "s")