Should CMakeLists.txt for the gigasecond exercise be updated?

Hello,

I just finished the gigasecond exercise on the C++ track. This exercise requires Boost, which I downloaded and unzipped to a local folder. I added the path to the header files in the INCLUDE environment variable.

Now when I ran cmake -S . -B build I got the following error:

Could NOT find Boost (missing: date_time) (found suitable version “1.80.0”,
minimum required is “1.58”)

Which was confusing because it states it found a suitable version, but somehow does not use it. I had similar problems with Boost 1.86.


I was able to fix this, on the Boost website it says:

Most Boost libraries are header-only : they consist entirely of header files containing templates and inline functions, and require no separately-compiled library binaries or special treatment when linking.

However CMakeLists.txt for the gigasecond exercise contains the following sections:

find_package(Boost 1.58 REQUIRED COMPONENTS date_time)

and

# We need boost libraries
target_link_libraries(${exercise}
PRIVATE
Boost::date_time
)

Those sections require library binaries for the date_time module, which may be there if you compile Boost or could be part of the Boost package (they were not in my case), but for a header-only library are probably not needed.

After commenting out those sections, I could compile and solve the gigasecond exercise.

So my question is: Should CMakeLists.txt for the gigasecond exercise be updated such that CMAKE does not start looking for library binaries it probably does not need and may not be able to find?


For reference: I am using Windows 11 Home and Visual Studio 2022 Express.

You have some good arguments. I have only done this exercise on Linux systems and never encountered that problem. There is another boost-requiring exercise, it is called meetup.

Would you be so kind and solve that one as well on your system and report on any cmake issues?

Hi, thanks for the quick reply.

I did a quick check of the meetup exercise. It also uses the Boost::date_time module and the issue is the same.

When I download the exercise and try to build, it fails. Then when I edit CMakeLists.txt (commenting the same sections as in my previous post), I can build.

I did not do the full exercise but wrote enough code to make the first test pass.
With this I could do the entire exercise.

Console session below (I had set the Boost_ROOT variable yesterday, to try to resolve the issue but it had no effect):

C:\git\Exercism\cpp [master ≡]> exercism download --track=cpp --exercise=meetup

Downloaded to
c:\git\exercism\cpp\meetup
C:\git\Exercism\cpp [master ≡ +1 ~0 -0 !]> cd .\meetup
C:\git\Exercism\cpp\meetup [master ≡ +1 ~0 -0 !]> cmake -S . -B build
– Building for: Visual Studio 17 2022
– Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
– The CXX compiler identification is MSVC 19.41.34120.0
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:13 (find_package):
Policy CMP0074 is not set: find_package uses _ROOT variables.
Run “cmake --help-policy CMP0074” for policy details. Use the cmake_policy
command to set the policy and suppress this warning.

Environment variable Boost_ROOT is set to:

C:\Program Files\boost\boost_1_80_0

For compatibility, CMake is ignoring the variable.
This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:13 (find_package):
Policy CMP0167 is not set: The FindBoost module is removed. Run “cmake
–help-policy CMP0167” for policy details. Use the cmake_policy command to
set the policy and suppress this warning.

This warning is for project developers. Use -Wno-dev to suppress it.

CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
Could NOT find Boost (missing: date_time) (found suitable version “1.80.0”,
minimum required is “1.58”)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.30/Modules/FindBoost.cmake:2409 (find_package_handle_standard_args)
CMakeLists.txt:13 (find_package)

– Configuring incomplete, errors occurred!
C:\git\Exercism\cpp\meetup [master ≡ +1 ~0 -0 !]> gvim .\CMakeLists.txt
C:\git\Exercism\cpp\meetup [master ≡ +1 ~0 -0 !]> cmake -S . -B build
– Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
– Configuring done (0.0s)
– Generating done (0.1s)
– Build files have been written to: C:/git/Exercism/cpp/meetup/build

Ok, I got both gigasecond and meetup running on Windows with the standard CMakeLists.txt. No changes needed. Sorry for the confusion.

Steps I took:

  • Download Boost 1.86.
  • Extract to C:\Program Files\Boost\boost_1_86_0
  • Set the INCLUDE environment variable to C:\Program Files\Boost\boost_1_86_0
  • Compile boost, as administrator in a “Developer Command Prompt” in the directory C:\Program Files\Boost\boost_1_86_0, run:
    • booststrap.bat
    • b2.exe

After these steps CMake can build both exercises with CMakeLists.txt that comes with the execises.

I thought I had done all of this earlier this week, but apparently I missed some steps.

Thanks for your time and sorry for the confusion.

This might be very valuable to other students.

I have some tabs open for ages with the boost installation pages and our installation guide and I wanted to update the latter to make it easier for windows users to use exercism with c++ locally. I even have working windows VM, but I never got to test the process.

Would you like to update our pages with a (well-enough detailed) rundown of your process so other people can read it?

Yes, I can look into it.

I am not sure though that what I describe above is what an experienced C++ developer on Windows would do, actually I am pretty sure it is not.

I have since found that there are several package managers with which one can install dependencies, e.g. vcpackage. I am looking into that currently. vcpackage is part of Visual Studio as is Boost.Test. So it should not be that hard. The only issue is integrating it with what is in the CMakeLists.txt that comes with the exercise.

I also found this link:

As far as I know, boost was a constant source of pain across all platforms, especially on windows.

The necessity of using boost has therefore removed from all exercises except a small number. All of those are related to time/date problems as far as I remember.

So issues with Boost on this track are not new.

I would describe the simplest way to install boost on windows, which is not necessary with a package manager when it is only supposed to manage one package.

Your way works and does not seem overly messy or complicated, so I would take this over not being able to solve the exercises.

Pain with boost is indeed not new, but it is often used in the C++ world. Removing it from our exercises would therefore only delay the user’s first confrontation with it.