0

I am writing a Linux program with Qt and boost, using cmake. Everything is fine there, but now I want to port this program to windows. Having installed cmake from here https://github.com/Kitware/CMake/releases/download/v3.20.5/cmake-3.20.5-windows-x86_64.msi and Qt by qt-opensource-windows-x86-5.12.11.exe (which is the offline installer with all frills). The Qt installation also did install a mingw environment. In my CMakeLists.txt, I search the boost libraries with

find_library(LIB_BOOST_FILESYSTEM "boost_filesystem")
find_library(LIB_BOOST_SYSTEM "boost_system")
find_library(LIB_BOOST_PROGRAM_OPTIONS "boost_program_options")

Then I installed boost like described here: https://gist.github.com/sim642/29caef3cc8afaa273ce6 using the toolchain gcc

I deviated from the description in that I placed the directories like this:

  1. Extracted boost source to C:\Users\picard\boost_1_70_0
  2. Created a folder for Boost.Build installation: C:\Users\picard\boost-build
  3. Created a folder within for building: C:\Users\picard\boost_1_70_0\build
  4. Created a folder for installation: C:\Users\picard\boost

Boost build and installation itself ran fine. I set the environment variables to

BOOST_INCLUDEDIR    C:\Users\picard\boost\include\boost_1_70\
BOOST_LIBRARYDIR    C:\Users\picard\boost\lib\
BOOST_ROOT          C:\Users\picard\boost_1_70_0\boost

I also tested changing the BOOST_ROOT to other values like C:\Users\picard\boost but I guess, I did not hit the correct one. The result is always the same:

CMake error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIB_BOOST_FILESYSTEM 
    linked by target "myprogram" in directory c:/Users/picard/myprogram
LIB_BOOST_PROGRAM_OPTIONS
    linked by target "myprogram" in directory c:/Users/picard/myprogram
LIB_BOOST_SYSTEM
    linked by target "myprogram" in directory c:/Users/picard/myprogram

The cmake-skripts for boost are located (I checked this) in the boost installation dir: c:\Users\picard\boost\lib\cmake

In the directory c:\Users\picard\boost\lib there are all the boost libraries I expect, following the name scheme: libboost_*-mgw73-mt-[d|]-x32-1_70.a I guess, the mt stands for multithreading, so I added

set(Boost_USE_MULTITHREADED ON)

to my CMakeLists.txt, but it did not change anything.

I also followed advices from here:

find_package() doesn't detect boost on Windows Cmake

Compiling C++ with Boost 1.68.0 on Windows using CMake and MinGW

CMake cannot find Boost on Windows

CMake does not find Boost on Custom Location on Windows

The only one which gives me more output is -DBoost_DEBUG=ON):

CMake Warning:
  Manually-specified variables were not used by the project:
  
    Boost_DEBUG

Maybe things changed recently, but I guess, I have set the wrong paths in my environment variables.

Thanks for you answers!

Update against hints by Tsyvarev: Changing the find_library() to find_package(), cmake tells me to set the policy CMP0074. I did so by adding cmake_policy(SET CMP0074 NEW) to my CMakeLists.txt This is a step forward, now there is a new output:

-- The CXX compiler identification is GNU 7.3.0
-- The C compiler identification is GNU 7.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Qt5.12.11/Tools/mingw730_32/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Qt5.12.11/Tools/mingw730_32/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Boost 1.70.0 at C:/Users/picard/boost/lib/cmake/Boost-1.70.0
--   Requested configuration: QUIET REQUIRED COMPONENTS filesystem
-- Found boost_headers 1.70.0 at C:/Users/picard/boost/lib/cmake/boost_headers-1.70.0
-- Found boost_filesystem 1.70.0 at C:/Users/picard/boost/lib/cmake/boost_filesystem-1.70.0
-- No suitable boost_filesystem variant has been identified!
--   libboost_filesystem-mgw73-mt-d-x32-1_70.a (mgw73, detected mgw7, set Boost_COMPILER to override)
--   libboost_filesystem-mgw73-mt-x32-1_70.a (mgw73, detected mgw7, set Boost_COMPILER to override)
CMake Error at C:/Users/picard/boost/lib/cmake/Boost-1.70.0/BoostConfig.cmake:95 (find_package):
  Found package configuration file:

    C:/Users/picard/boost/lib/cmake/boost_filesystem-1.70.0/boost_filesystem-config.cmake

  but it set boost_filesystem_FOUND to FALSE so package "boost_filesystem" is
  considered to be NOT FOUND.  Reason given by package:
 
  No suitable build variant has been found.

Call Stack (most recent call first):
  C:/Users/picard/boost/lib/cmake/Boost-1.70.0/BoostConfig.cmake:124 (boost_find_dependency)
  C:/Program Files/CMake/share/cmake-3.20/Modules/FindBoost.cmake:594 (find_package)
  CMakeLists.txt:34 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/Users/picard/myprogram/build/CMakeFiles/CMakeOutput.log".

The problem is now the compiler identification (mgw73 vs. mgw7) mismatch. Using set(Boost_COMPILER "mgw73"), the message stays the same, using set(Boost_COMPILER "mgw7"), the message changes to

--   libboost_filesystem-mgw73-mt-d-x32-1_70.a (mgw73, Boost_COMPILER=mgw7)
--   libboost_filesystem-mgw73-mt-x32-1_70.a (mgw73 Boost_COMPILER=mgw7)

I have only one MinGW (7.3) installed, and used this installed MinGW to build boost.

  • Variables like `BOOST_INCLUDEDIR`, `BOOST_LIBRARYDIR` affects only on [find_package(Boost)](https://cmake.org/cmake/help/latest/module/FindBoost.html). These variables have no effect on plain `find_library` calls. – Tsyvarev Jul 14 '21 at 10:43
  • So ``find_library`` is not the way to go? – Dirk Neumann Jul 14 '21 at 10:55
  • If you ask whether one can **able** find Boost libraries via `find_library`, then the answer is "yes, but [find_library](https://cmake.org/cmake/help/latest/command/find_library.html) requires its own hints". If you ask whether `find_library` is the **good** way for find Boost libraries, then the answer is "no, `find_package(Boost)` is always preferable way". – Tsyvarev Jul 14 '21 at 11:02

1 Answers1

0

I had exactly the same problem, but with mgw131 and mgw13:

Boost_COMPILER mgw131

-- No suitable boost_random variant has been identified!
-- libboost_random-mgw131-mt-d-x64-1_70.a (mgw131, detected mgw13, set Boost_COMPILER to override)

Boost_COMPILER -mgw131

-- No suitable boost_random variant has been identified!
-- libboost_random-mgw131-mt-d-x64-1_70.a (mgw131, Boost_COMPILER=-mgw131)

Boost_COMPILER -mgw13

-- No suitable boost_random variant has been identified!
-- libboost_random-mgw131-mt-d-x64-1_70.a (mgw131, Boost_COMPILER=-mgw13)

Boost_COMPILER mgw13

-- No suitable boost_random variant has been identified!
-- libboost_random-mgw131-mt-d-x64-1_70.a (mgw131, Boost_COMPILER=mgw13)

Taking a look to cmake file, I saw this:

if(Boost_COMPILER AND NOT Boost_COMPILER STREQUAL "mgw131")
  _BOOST_SKIPPED("libboost_random-mgw131-mt-d-x64-1_70.a" "mgw131, Boost_COMPILER=${Boost_COMPILER}")
  return()
endif()

if(BOOST_DETECTED_TOOLSET AND NOT BOOST_DETECTED_TOOLSET STREQUAL "mgw131")
  _BOOST_SKIPPED("libboost_random-mgw131-mt-d-x64-1_70.a" "mgw131, detected ${BOOST_DETECTED_TOOLSET}, set Boost_COMPILER to override")
  return()
endif()

I solved the problem by setting "mgw13" value to Boost_COMPILER and BOOST_DETECTED_TOOLSET just before calling find_package and running updatelibboost_toolset.sh script:

# Find the package and import the target 
if(WIN32 OR MINGW)
    SET(Boost_DEBUG ON)
    # set Boost_COMPILER to mgw13, to avoid (mgw131, detected mgw13, set Boost_COMPILER to override) error with boost_random
    message(STATUS "[build_cots.cmake]: set 'mgw13' value to Boost_COMPILER and BOOST_DETECTED_TOOLSET for Windows")
    set(Boost_COMPILER "mgw13")
    set(BOOST_DETECTED_TOOLSET "mgw13")
    # change cmake mgw version from mgw131 to mgw13 to make it work
    execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/cots/updatelibboost_toolset.sh
                WORKING_DIRECTORY "${CMAKE_INSTALL_DIR}/Boost/lib/cmake"
                COMMAND_ECHO STDOUT 
                COMMAND_ERROR_IS_FATAL ANY)
endif()
message(STATUS "[build_cots.cmake]: Boost_COMPILER ${Boost_COMPILER}")
message(STATUS "[build_cots.cmake]: BOOST_DETECTED_TOOLSET ${BOOST_DETECTED_TOOLSET}")
find_package(Boost REQUIRED COMPONENTS math random system thread filesystem chrono atomic regex date_time PATHS "${CMAKE_CURRENT_BINARY_DIR}/ExternalProject/Install/Boost")

updatelibboost_toolset.sh script replace "mgw131 by "mgw13 because, even if you change the value of BOOST_DETECTED_TOOLSET, it will recover "mgw13" value. This script make replacement in all files that includes "mgw131" on their name:

#!/bin/bash
echo Running updatelibboost_random.sh
# Recursively search for files that contain "mgw131" in the name
find . -type f -name "*mgw131*" -print0 | while IFS= read -r -d $'\0' file
do
  sed -i 's/"mgw131/"mgw13/g' "$file"
done

And know it's working fine