# Using boost in a modern way static AND shared

**URL:** <https://discourse.cmake.org/t/using-boost-in-a-modern-way-static-and-shared/6680>\
**Category:** Code\
**Created:** [October 17, 2022, 3:02pm UTC](https://discourse.cmake.org/t/using-boost-in-a-modern-way-static-and-shared/6680 "2022-10-17T15:02:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Post date:** [October 17, 2022, 3:02pm UTC](https://discourse.cmake.org/t/using-boost-in-a-modern-way-static-and-shared/6680/1 "2022-10-17T15:02:10Z")

</div>

I have an existing project that uses boost heavily and am converting to CMake.  
As a hand crafted project it uses nuget and I just cannot figure out how to make that work and I really do not want to as the linux build does not (maintaining 2 build systems atm). I am using

```auto
    set(CMAKE_PREFIX_PATH ${BOOST_ROOT}/stage)
    message (" Looking for boost in ${BOOST_ROOT}")
    set(Boost_NO_SYSTEM_PATHS ON)
    find_package(Boost ${Boost_VER} CONFIG REQUIRED COMPONENTS date_time thread filesystem system regex)

```

I built a complete build and all the projects except one can find and use boost. That one project is /MT instead of /MD and uses boost::asio.  
When I use this more modern CMake way and add the targets to the projects target\_link\_libraries, I am also adding the PreProcessor definitions and the include directories but I seem to be missing something.

This works for all other targets. (static,shared and an executable)

```auto
 target_link_libraries( ${PROJECT_NAME}
   ...
    Boost::headers
    Boost::dynamic_linking
  ...

```

But this does not work for the staticaly linked /MT add\_executable

```auto
target_link_libraries( ${PROJECT_NAME} 
                        ...
                        Boost::headers
                        Boost::date_time
                        Boost::filesystem
                        Boost::regex
                        Boost::system
                        ...

```

Is this how I am suppose to bring in the properties, include paths and libnames for the statically linked boost libs?

I have not actually gotten to linking, It is compile errors about identifiers not found which I can aliviate temporarily that then shows the wrong boost library type is trying to be used and so I am thinking the includes are wrong. I tried making the command line for the buidl the same but the full paths make that not possible.

(Boost 1.76, CMAke 3.23, VS2019 V142 x64)

Thanks.

---

<div class="post-metadata">

**Author:** ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Post date:** [October 17, 2022, 6:29pm UTC](https://discourse.cmake.org/t/using-boost-in-a-modern-way-static-and-shared/6680/2 "2022-10-17T18:29:30Z")

</div>

I found in the doc that this will not work in this way. That which was found on first usage will not be overwritten on a second find and the Boost::dynamic linking works for the boost libraries and NOT the C runtime linking.

The old method is suppose to work but it still seems to ALWAYS get the library wrong.  
☹
