【问题标题】:How to adapt FindBoost.cmake static library search for x32 boost libs?如何使 FindBoost.cmake 静态库搜索适应 x32 增强库?
【发布时间】:2019-09-13 16:32:14
【问题描述】:

问题:

我正在尝试在我的项目中包含一个自建的 boost 库。我正在使用 cmake 构建文件,并且遇到 Findboost.cmake 找不到已编译库的问题。如果您查看 cmake 调试信息,它似乎在搜索错误的库名称。

这里是一个错误库名的例子:

目前:

  • libboost_regex-mgw82-mt-d-1_71

想要的:

  • libboost_regex-mgw82-mt-d-x32-1_71

我的意思是我可以手动重命名文件,但我认为这不是唯一的解决方案。有什么办法可以告诉 cmake 添加“x32”部分吗?或者也许我必须给 boost 一个特殊的编译输入?

Cmake 文件和命令:

cmake_minimum_required(VERSION 3.14)
project(clion)

set(CMAKE_CXX_STANDARD 14)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.71.0 COMPONENTS regex REQUIRED)

if (Boost_FOUND)

    include_directories(${Boost_INCLUDE_DIRS})
    add_executable(clion main.cpp)
    target_link_libraries(clion ${Boost_LIBRARIES})

endif ()
cmake -G "MinGW Makefiles" -DBoost_DEBUG=TRUE .

调试输出:

这是完整的输出:

    cmake -G "MinGW Makefiles" -DBoost_DEBUG=TRUE .
    -- The C compiler identification is GNU 8.2.0
    -- The CXX compiler identification is GNU 8.2.0
    -- Check for working C compiler: D:/Programme/MINGW64/bin/gcc.exe
    -- Check for working C compiler: D:/Programme/MINGW64/bin/gcc.exe -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: D:/Programme/MINGW64/bin/g++.exe
    -- Check for working CXX compiler: D:/Programme/MINGW64/bin/g++.exe -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1427 ] _boost_TEST_VERSIONS = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1428 ] Boost_USE_MULTITHREADED = "ON"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1429 ] Boost_USE_STATIC_LIBS = "ON"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1430 ] Boost_USE_STATIC_RUNTIME = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1431 ] Boost_ADDITIONAL_VERSIONS = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1432 ] Boost_NO_SYSTEM_PATHS = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1501 ] BOOST_ROOT = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1502 ] ENV{BOOST_ROOT} = "E:\programming\cpp\libs\boost\boost_1_71_0"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1503 ] BOOST_INCLUDEDIR = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1504 ] ENV{BOOST_INCLUDEDIR} = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1505 ] BOOST_LIBRARYDIR = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1506 ] ENV{BOOST_LIBRARYDIR} = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1578 ] _boost_INCLUDE_SEARCH_DIRS = "E:/programming/cpp/libs/boost/boost_1_71_0/include;E:/programming/cpp/libs/boost/boost_1_71_0;PATHS;C:/boost/include;C:/boost;/sw/local/include"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1579 ] _boost_PATH_SUFFIXES = <unset>
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1594 ] location of version.hpp: E:/programming/cpp/libs/boost/boost_1_71_0/boost/version.hpp
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1634 ] Boost_VERSION = "107100"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1635 ] Boost_VERSION_STRING = "1.71.0"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1636 ] Boost_VERSION_MACRO = "107100"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1637 ] Boost_VERSION_MAJOR = "1"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1638 ] Boost_VERSION_MINOR = "71"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1639 ] Boost_VERSION_PATCH = "0"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1640 ] Boost_VERSION_COUNT = "3"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1657 ] Boost_LIB_PREFIX = "lib"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1658 ] Boost_NAMESPACE = "boost"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:766 ] _boost_COMPILER = "-mgw82" (guessed)
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1694 ] _boost_MULTITHREADED = "-mt"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1771 ] _boost_ARCHITECTURE_TAG = "" (detected)
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1775 ] _boost_RELEASE_ABI_TAG = "-"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1776 ] _boost_DEBUG_ABI_TAG = "-d"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1836 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "E:/programming/cpp/libs/boost/boost_1_71_0/lib;E:/programming/cpp/libs/boost/boost_1_71_0/stage/lib;E:/programming/cpp/libs/boost/boost_1_71_0/lib;E:/programming/cpp/libs/boost/boost_1_71_0/../lib;E:/programming/cpp/libs/boost/boost_1_71_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1837 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "E:/programming/cpp/libs/boost/boost_1_71_0/lib;E:/programming/cpp/libs/boost/boost_1_71_0/stage/lib;E:/programming/cpp/libs/boost/boost_1_71_0/lib;E:/programming/cpp/libs/boost/boost_1_71_0/../lib;E:/programming/cpp/libs/boost/boost_1_71_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
    CMake Warning at D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1125 (message):
      New Boost version may have incorrect or missing dependencies and imported
      targets
    Call Stack (most recent call first):
      D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1247 (_Boost_COMPONENT_DEPENDENCIES)
      D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:1885 (_Boost_MISSING_DEPENDENCIES)
      CMakeLists.txt:7 (find_package)


    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:2021 ] Searching for REGEX_LIBRARY_RELEASE: libboost_regex-mgw82-mt-1_71;libboost_regex-mgw82-mt;libboost_regex-mgw82-mt;libboost_regex-mt-1_71;libboost_regex-mt;libboost_regex-mt;libboost_regex-mt;libboost_regex;libboost_regex-mgw82-mt-s-1_71;libboost_regex-mgw82-mt-s;libboost_regex-mgw82-mt-s;libboost_regex-mt-s-1_71;libboost_regex-mt-s;libboost_regex-mt-s
    -- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:2076 ] Searching for REGEX_LIBRARY_DEBUG: libboost_regex-mgw82-mt-d-1_71;libboost_regex-mgw82-mt-d;libboost_regex-mgw82-mt-d;libboost_regex-mt-d-1_71;libboost_regex-mt-d;libboost_regex-mt-d;libboost_regex-mt;libboost_regex;libboost_regex-mgw82-mt-s-d-1_71;libboost_regex-mgw82-mt-s-d;libboost_regex-mgw82-mt-s-d;libboost_regex-mt-s-d-1_71;libboost_regex-mt-s-d;libboost_regex-mt-s-d
    CMake Error at D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
      Could NOT find Boost (missing: regex) (found suitable version "1.71.0",
      minimum required is "1.71.0")
    Call Stack (most recent call first):
      D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
      D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:2142 (find_package_handle_standard_args)
      CMakeLists.txt:7 (find_package)


    -- Configuring incomplete, errors occurred!
    See also "E:/programming/cpp/clion/CMakeFiles/CMakeOutput.log".

我认为这是重要的部分:

-- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:2021 ]  
Searching for REGEX_LIBRARY_RELEASE: libboost_regex-mgw82-mt-1_71;libboost_regex-mgw82-mt;libboost_regex-mgw82-mt;libboost_regex-mt-1_71;libboost_regex-mt;libboost_regex-mt;libboost_regex-mt;libboost_regex;libboost_regex-mgw82-mt-s-1_71;libboost_regex-mgw82-mt-s;libboost_regex-mgw82-mt-s;libboost_regex-mt-s-1_71;libboost_regex-mt-s;libboost_regex-mt-s
-- [ D:/Programme/CMake/cmake-3.15.2-win64-x64/share/cmake-3.15/Modules/FindBoost.cmake:2076 ]  
Searching for REGEX_LIBRARY_DEBUG: libboost_regex-mgw82-mt-d-1_71;libboost_regex-mgw82-mt-d;libboost_regex-mgw82-mt-d;libboost_regex-mt-d-1_71;libboost_regex-mt-d;libboost_regex-mt-d;libboost_regex-mt;libboost_regex;libboost_regex-mgw82-mt-s-d-1_71;libboost_regex-mgw82-mt-s-d;libboost_regex-mgw82-mt-s-d;libboost_regex-mt-s-d-1_71;libboost_regex-mt-s-d;libboost_regex-mt-s-d

【问题讨论】:

    标签: c++ boost cmake


    【解决方案1】:

    试试:

    set(Boost_COMPILER "-x32")
    

    根据FindBoost reference

    Boost_COMPILER           - Set to the compiler-specific library suffix
                               (e.g. "-gcc43").  Default is auto-computed
                               for the C++ compiler in use.
    

    正如@kenba 所建议的,Boost_ARCHITECTURE 也可以工作并且在技术上更正确。

    【讨论】:

    • 您的建议确实是解决我的问题。对我来说,这只是“-x32”部分!非常感谢!
    【解决方案2】:

    我认为您的问题是由FindBoost.cmake 未在boost 1.66.0 及以上版本中正确处理MinGw 库名称引起的,如答案here 中所述。

    set(Boost_ARCHITECTURE "-x32") 添加到您的CMakeLists.txt 文件或将-DBoost_ARCHITECTURE="-x32" 添加到您的cmake 命令应该可以修复它。

    【讨论】:

    • 非常感谢您的回答!这也解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2012-12-16
    • 2011-05-24
    • 2021-07-29
    相关资源
    最近更新 更多