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:
- Extracted boost source to
C:\Users\picard\boost_1_70_0
- Created a folder for Boost.Build installation:
C:\Users\picard\boost-build
- Created a folder within for building:
C:\Users\picard\boost_1_70_0\build
- 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.