
I am need to use boost unit_test_framework and I am using Cmake command to find it:
cmake_minimum_required(VERSION 3.15) project(My_String) set(CMAKE_CXX_STANDARD 17) set(Boost_USE_STATIC_LIBS OFF) set(SOURCE_FILES MyStringTest.cpp) set(BOOST_ROOT "C:\\Program Files\\boost\\boost_1_71_0") find_package(Boost REQUIRED COMPONENTS unit_test_framework) include_directories(${Boost_INCLUDE_DIR}) include_directories(../src) add_executable (Boost_Tests_run ${SOURCE_FILES}) target_link_libraries (Boost_Tests_run Boost::unit_test_framework)
I get this error:
Could NOT find Boost (missing: unit_test_framework) (found version "1.71.0")
What can I do to fix it?
72 Answers
As Real Fresh suggested to use vcpkg mananger https://github.com/microsoft/vcpkg And So I gave it a try, I faced couple of issues but after that It worked so what I did is:
1.install vcpkg https://github.com/microsoft/vcpkg (Follow the instructions) You migh have the error when setting up (Fatal error, could not do post-extract operation renaming 'File' to 'Different name' ) You need to rename the manually.
2.install boost-test lib (you will see instruction on how to install packages) on the home page of vcpkg
3.you need to set these variables for cmake:
-DVCPKG_TARGET_TRIPLET=x86-windows (x86-windows in my case) "-DCMAKE_TOOLCHAIN_FILE='root to vcpkg'/scripts/buildsystems/vcpkg.cmake" (in my case root to vcpkg = F:/Files/vcpkg so the variable will be: "-DCMAKE_TOOLCHAIN_FILE=F:/Files/vcpkg/scripts/buildsystems/vcpkg.cmake"
4.in your test/cmakelists.txt file you need to add the following:
find_package (Boost REQUIRED COMPONENTS unit_test_framework) target_link_libraries (your_test_exe Boost::unit_test_framework)
in my case I have my test/cmakelists.txt like this:
cmake_minimum_required(VERSION 3.15) project(My_String) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "--coverage" ) set(SOURCE_FILES MyStringTest.cpp) set(Boost_DEBUG ON) find_package (Boost REQUIRED COMPONENTS unit_test_framework) include_directories(../Src) add_executable (Boost_Tests_run ${SOURCE_FILES}) target_link_libraries (Boost_Tests_run Boost::unit_test_framework)
5.In your test.cpp you need to include:
#include <boost/test/included/unit_test.hpp> as it is! in addition to the classes you are testing.
in my case it looks like this:
#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE MyString_Test_Suite #include #include "MyString.h" #include "MyString.cpp" #include <boost/test/included/unit_test.hpp>
After more than a week of googling, trial and error this finally worked for me! Hope it helps if any one face the same issue. Thank you Real Fresh for your support!
I had resolved the same error message with apt-get install libboost-all-dev
on my Ubuntu 20 machine.
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobHJpaG6CeH%2BOnKaupJRiu7DAjJ%2Bgp5xdl7ywv9NmpKKro567qHnUp6CtZaSawLV5xauYpp2npL%2BsecWorKecXauys7%2FIqKVmaV1sfm58