Cmake cannot find Boost libraries

后端 未结 3 500
说谎
说谎 2020-12-09 21:31

I am new to Cmake and boost libraries in C++. I am working on a project that needs boost and Cmake. I am using Cmake version 2.8.11, MS Visual Studio 2013 and Boost 1.54.0.

3条回答
  •  再見小時候
    2020-12-09 22:04

    Your configuration looks a bit weird and dirty. Especially things like:

    ADD_DEFINITIONS(-DBoost_USE_STATIC_LIBS=ON)
    

    It's not a C/C++ preprocessor definition! It's a CMake variable which is used to control how CMake will define the linkage stage of your project with Boost libraries.

    If you properly compiled Boost and didn't mess up anything, then the directory structure usually looks like this:

    
      include
        boost
          accumulators
          ...
          aligned_storage.hpp
          ...
      lib
        libboost_atomic-mt-s.a
        ...
    

    NOTE: The root directory of Boost, , appears to be D:/boost_1_54_0 in your case.

    If in your case it does not look like above, then I'd suggest to rearrange it manually to the one above since, once again, this is how it should be.

    When done, let's do some CMake configuration. I suggest to keep things simple and clean in the first place, and obey the CMake conventions. Test the following:

    set(BOOST_INCLUDEDIR D:/boost_1_54_0/include)
    set(BOOST_LIBRARYDIR D:/boost_1_54_0/lib)
    

    NOTE: You can find thorough description of both of these variables at the top of FindBoost.cmake.

    set(Boost_USE_STATIC_LIBS   ON)
    set(Boost_USE_MULTITHREADED ON)
    

    NOTE: This is how you enforce static linkage by setting the CMake variable properly, but not like you did by setting a non-existent C/C++ preprocessor definition.

    find_package(Boost
                 1.54.0
                 COMPONENTS thread
                            system
                            log
                            log_setup
                            program_options
                 REQUIRED)
    
    include_directories(${Boost_INCLUDE_DIRS})
    
    target_link_libraries( ${Boost_LIBRARIES})
    

    NOTE: Instead of , put the name of the target that you wish to build (executable, static/shared library, etc.).

提交回复
热议问题