代码之家  ›  专栏  ›  技术社区  ›  Paul Belanger

cmake findboost.cmake mingw-w64:正在搜索名称不正确的库

  •  3
  • Paul Belanger  · 技术社区  · 6 年前

    我已经建立了Boost 1.68(使用 https://gist.github.com/sim642/29caef3cc8afaa273ce6 ,并添加 link=static,shared 到b2命令行,也可以构建共享库。)

    库似乎构建正确,我已经设置了 BOOST_INCLUDEDIR BOOST_LIBRARYDIR 环境变量正确。

    但是,当我将以下内容添加到 CMakeLists.txt :

    find_package(Boost REQUIRED COMPONENTS system context coroutine thread random REQUIRED)
    

    和生成 MinGW Makefiles

    CMake Error at C:/Users/pbelanger/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/182.4129.15/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:2044 (message):
      Unable to find the requested Boost libraries.
    
      Boost version: 1.68.0
    
      Boost include path: C:/boost/install/include/boost-1_68
    
      Could not find the following static Boost libraries:
    
              boost_system
              boost_context
              boost_coroutine
              boost_thread
              boost_random
    
      Some (but not all) of the required Boost libraries were found.  You may
      need to install these additional Boost libraries.  Alternatively, set
      BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
      to the location of Boost.
    

    set(Boost_DEBUG ON) find_package https://pastebin.com/yRd5DPt4

    c:\boost\install\lib system libboost_system-mgw81-mt-x64-1_68.dll boost_system-mgw81-mt-1_68 find_library -x64

    2 回复  |  直到 6 年前
        1
  •  3
  •   Federico Terzi    6 年前

    经过数小时的研究,保罗贝朗格给出的答案挽救了我的一天。

    在代码库中进一步挖掘,他们添加了一个新的选项来精确管理这个案例,因此使用最新版本的cmake,您可以添加以下选项:

    set (Boost_ARCHITECTURE "-x64")
    

    资料来源: https://github.com/Kitware/CMake/commit/1e08b625c291e0bb57d253b6656e812dc8848bd8#diff-555801259d7df67368f7deab1f9deacd

        2
  •  3
  •   Paul Belanger    6 年前

    看看 FindBoost.cmake , line 1478 , 脚本将查看 CMAKE_CXX_COMPILER_ARCHITECTURE_ID 整齐 构建正确的体系结构标记。但是,在我的编译器(mingw-w64 8.1)上 64位),此字符串为空。因此,架构标记被省略。

    我必须手动设置这个变量的值,方法是 在我之前 find_package 线:

    if(WIN32 AND "x${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "x")
        message(WARNING "WIN32 compiler does not specify CMAKE_CXX_COMPILER_ARCHITECTURE_ID -- filling in manually")
        if(CMAKE_SIZEOF_VOID_P EQUAL 8)
            set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID "x64")
        else()
            set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID "x86")
        endif()
        message(STATUS "Compiler architecture: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
    endif()
    
    # now we should be able to find boost correctly. 
    find_package(Boost REQUIRED COMPONENTS system context coroutine thread random REQUIRED)
    

    这使得find_包工作正常。