3

Problem:

I'm trying to include a self-built boost library into my project. I'm using a cmake buildfile and im running into the problem that Findboost.cmake cannot find the compiled libraries. If you look at the cmake debug information it seems to search for the wrong library names.

Here is an example of what i mean with wrong library name:

currently:

  • libboost_regex-mgw82-mt-d-1_71

desired:

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

I mean I could rename the files manually but I don't think that's the only solution. Is there any way I can tell cmake to add the "x32" part? Or maybe I have to give boost a special input for compilation?

Cmake File & Command:

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 .

Debug Output:

Here is the full output:

    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".

I think this is the important part:

-- [ 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
Lapeus
  • 33
  • 5

2 Answers2

1

Try:

set(Boost_COMPILER "-x32")

According to the FindBoost reference:

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

As suggested by @kenba, Boost_ARCHITECTURE may also work and be technically more correct.

jdonald
  • 670
  • 7
  • 15
  • Your suggestion is indeed the solution to my problem. For me it was only the "-x32" part! Thank you very much! – Lapeus Sep 15 '19 at 18:23
1

I believe that your issue is caused by FindBoost.cmake not handling MinGw boost library names correctly in boost versions from 1.66.0 onwards as described in the answer here.

Adding set(Boost_ARCHITECTURE "-x32") to your CMakeLists.txt file or adding -DBoost_ARCHITECTURE="-x32"to your cmake command should fix it.

kenba
  • 4,303
  • 1
  • 23
  • 40