How can I link Boost to CMake and Visual Studio on Windows?

I am trying to create some Boost 1.58 libraries that I need (chrono, regex and thread) for Visual Studio 2012, and link the libraries to CMake. I have real problems for CMake and Visual Studio to find or link libraries, depending on the configuration I installed.

Finally, I use the following configuration:

bjam.exe --link = static --threading multi --variant = debug phase

But this is not like creating static libs.

How can I generate libraries and search for them using CMake so that Visual Studio correctly links them?

+4
source share
2 answers

- , , , .

Visual Studio , Boost , , , . bjam.exe "-" , :

bjam.exe link=shared --threading=multi --variant=debug --variant=release --with-chrono --with-regex --with-thread stage

libs DLL Boost/stage/lib, , , Boost_LIBRARY_DIR C:/Boost/stage/lib.

, :

runtime-link = shared/static
toolset= msvc-11.0

:

boost_chrono-vc110-mt-1_58.lib
boost_chrono-vc110-mt-1_58.dll

:

boost_chrono-vc110-mt-gd-1_58.lib
boost_chrono-vc110-mt-gd-1_58.dll

CMake , CMakeLists.txt:

    add_definitions( -DBOOST_ALL_DYN_LINK )  //If not VS will give linking errors of redefinitions
    set(Boost_USE_STATIC_LIBS OFF )
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_USE_STATIC_RUNTIME OFF)
    find_package(Boost COMPONENTS thread chrono regex REQUIRED )

    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})

    TARGET_LINK_LIBRARIES( ${PROJ_NAME} ${Boost_LIBRARIES} )  
+6

bjam.exe --link = static --threading multi --variant =

libs.

. stage\lib\ Boost. Boost Windows

CMake

SET (CMAKE_BUILD_TYPE Debug) # in order to link with boost debug libs you may need to set that to build your program in debug mode (or do that from command line)

FIND_PACKAGE (Boost 1.58 COMPONENTS "chrono" "regex" "thread" REQUIRED)

#ADD_DEFINITIONS(-DBOOST_ALL_DYN_LINK) # make sure you don't have this as it will try to link with boost .dll's

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

TARGET_LINK_LIBRARIES(${EXE_OR_LIB_NAME} ${Boost_LIBRARIES})
+2

All Articles