oost is a popular library for C++ programming that provides a wide range of functionalities and features. However, installing and using Boost on different operating systems can be challenging. In this article, we will compare and contrast the steps required to make Boost work on Windows and Mac. We will see that Mac has a simpler process, as it only involves building the library and adding it to the system path. On the other hand, Windows requires some additional steps and configurations to successfully use Boost..
I. Downloading Boost Source Code
There are two options for downloading Boost from the website: either download the source code and build it yourself, which is what we will do in this tutorial, or download the pre-built Windows binaries.
II. Generating the Boost Installer file “b2.exe”
On Pc. All what we have to do it to click on the bootstrap.bat.
This will generate the b2.exe
b2.exe is a command-line interface (CLI) file that we will use to build Boost 2. After generating the b2.exe file, we need to get its path. If you have Windows 11, you can easily right-click on the file and select “Copy path”.
Or you
can copy the path from the path-bar
III. Installing Boost On Windows
Next, we need to open the Terminal and navigate to the folder where the b2.exe file is located. For example, in my case, the folder path is:
cd "C:\Users\User_Name\Desktop\boost_1_XX_X"
Installing Boost, to install boost all what you have to do is to run this command at your terminal, after navigating to the boost folder that contain the b2.exe file
.\b2.exe install
After this process end we will find boost installation at
C:\Boost
IV. Adding Boost To The Path Environment
The final and crucial step is to set the BOOST_ROOT, BOOST_LIBRARY, and BOOST_INCLUDE variables in the Environment Variables. To do this, we need to access the Environment Variable window.
you will need to search in the search-bar for Environment Variables
Next, we will set the Boost paths in the Environment Variables. We will start with the BOOST_ROOT variable, which will point to the root of the Boost folder. For example:
BOOST_ROOT = C:\Boost
Then, we will set the BOOST_INCLUDE variable, which will point to the Boost include headers. For example:
BOOST_INCLUDE = C:\Boost\include\boost-1_XX
Note: The headers must be inside the Boost folder, so the header path must follow this format: boost/header_files.hpp
Finally, we will set the BOOST_LIBRARY variable, which will point to the Boost libraries. For example:
BOOST_LIBRARY = C:\Boost\lib
And you need to add them one by one, as follow.
- Click on the New button on the User Variables for Username
- After clicking New a window will pop-up with 2 inputs
- Variable Name: it’s the name of the variable you will use to call Boost on your CMake or any other builder manager. In our case is BOOST_ROOT
- Variable Value: Is the target path to the Boost Root C:/Boost.

And that is it all you need to make boost work on windows.
and this is an Example using it in my CMakeLists.txt
Code Box
cmake_minimum_required(VERSION 3.21)project(DSA VERSION 1.0.0 LANGUAGES CXX)# ========= Set C++ standardset(CMAKE_CXX_STANDARD 17)set(CMAKE_CXX_STANDARD_REQUIRED ON)if(WIN32)# ========= Set Boost Librariesset(Boost_LIBRARY_DIR $ENV{BOOST_LIB})set(Boost_INCLUDE_DIR $ENV{BOOST_INCLUDE})elseif(APPLE)# ========= Set Boost Librariesset(Boost_LIBRARY_DIR "/Users/username/Documents/boost/testing/lib")set(Boost_INCLUDE_DIR "/Users/username/Documents/boost")endif()# ========= Set directoriesset(SOURCE_DIR "${CMAKE_SOURCE_DIR}/src")set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")# ========= Include directoriesinclude_directories(${SOURCE_DIR})include_directories(${INCLUDE_DIR})include_directories(${Boost_INCLUDE_DIR})# ========= Add directories filesfile(GLOB_RECURSE SOURCES"${SOURCE_DIR}/*.cpp""${INCLUDE_DIR}/*.h")# ========= Include librariesfind_package(Boost COMPONENTS random filesystem system REQUIRED)# ========= Add executableadd_executable(${CMAKE_PROJECT_NAME}${SOURCES})# ========= Cnfigure macOS packageif(APPLE)set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE)endif()# ========= Link target subDirectoriestarget_link_directories(${CMAKE_PROJECT_NAME} PUBLIC src)target_link_directories(${CMAKE_PROJECT_NAME} PUBLIC include)target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${Boost_LIBRARY_DIR})# ========= Link libraries# if(WIN32)# target_link_libraries(${CMAKE_PROJECT_NAME}# Boost::random# Boost::filesystem# Boost::system# )# elseif(APPLE)target_link_libraries(${CMAKE_PROJECT_NAME}Boost::randomBoost::filesystemBoost::system)# endif()
Github_Repo : DSA Cryptography











0 Comments
Post a Comment