Cmake FindBoost.cmake MinGW-W64:搜索名称不正确的库

Pau*_*ger 4 c++ windows boost cmake cmake-modules

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

库似乎正确构建,并且我已经正确设置了BOOST_INCLUDEDIRBOOST_LIBRARYDIR环境变量。

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

find_package(Boost REQUIRED COMPONENTS system context coroutine thread random REQUIRED)
Run Code Online (Sandbox Code Playgroud)

并生成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.
Run Code Online (Sandbox Code Playgroud)

我将添加的输出放在此处set(Boost_DEBUG ON)find_package行之前:https : //pastebin.com/yRd5DPt4

根据调试输出,find脚本正在正确的目录(c:\boost\install\lib)中进行搜索,但未找到boost库,因为它们具有不同的命名方案。例如,该system库名为libboost_system-mgw81-mt-x64-1_68.dll,但是查找脚本会将其库名传递boost_system-mgw81-mt-1_68给CMake的find_library。请注意,寻址模型(-x64)没有在后一个名称中列出。

我的问题是这是否与Boost或findCMake脚本有关?是否可以通过在findCMake脚本之前设置特定的cmake变量来解决此问题?

Pau*_*ger 5

查看FindBoost.cmake第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)
Run Code Online (Sandbox Code Playgroud)

这使find_package正常工作。


Fed*_*rzi 5

经过数小时的研究,Paul Belanger给出的答案挽救了我的生命。

在代码库中进行了更多研究,他们添加了一个新选项来管理这种情况,因此,使用最新版本的CMAKE,您可以添加以下选项:

set (Boost_ARCHITECTURE "-x64")
Run Code Online (Sandbox Code Playgroud)

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