Build Boost
Boost-1.80.0
Boost in static runtime
- Download boost repo
git clone git submodule update --init --recursive git checkout boost-1.80.0 -
Download source code directly. Then extract.
-
Open the correct Developer Command Prompt x64 Native Tools Command Prompt for VS2022 (or 64-bit Developer Command Prompt). This ensures MSVC is detected. Check if terminal works well by
where clandecho %VSCMD_ARG_TGT_ARCH%that give x64. - Go to Boost root. Force rebuild and install only the libraries you need
bootstrap.bat
Using ‘vc143’ toolset.
So msvc14.3 is used for toolset that means Visual Studio 2022.
b2 -a toolset=msvc address-model=64 runtime-link=static link=static threading=multi variant=release,debug --with-regex --with-program_options --with-system --with-filesystem --prefix="C:\Users\hechr\software\boost-1.80-mt" install
b2 toolset=msvc address-model=64 runtime-link=static link=static threading=multi variant=release,debug stage
After installation, you can find the library file under lib folder, like libboost_system-vc143-mt-s-x64-1_80.lib
vc143: Visual studio 2022-s: static runtime/MT-mt: multithreaded
Check if static runtime library by
dumpbin /directives "C:\Users\hechr\software\boost-1.80-mt\lib\libboost_system-vc143-mt-s-x64-1_80.lib" | findstr DEFAULTLIB
LIBCMT shall be used.
Sometimes, there is no libraries in installation folder since no libraries are compiled successfully
- clean previous compile
b2 --clean rmdir /s /q bin.v2 rmdir /s /q stage - check error related to build
b2 toolset=msvc --debug-configuration- If the error related to VS Developer Command Prompt. You can switch to x64 Native Tools Command Prompt by the following command,
"C:\Program Files\Microsoft Visual Studio\2022\Community\vc\Auxiliary\Build\vcvars64.bat"
Make sure
cl.exeis matched. If you want to skip the automatic process to call cl.exe. To modifyproject-config.jamat current source root, like# Boost.Build Configuration # Automatically generated by bootstrap.bat import option ; using msvc : 14.3 : "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.44.35207\\bin\\Hostx64\\x64\\cl.exe" ; option.set keep-going : false ; - If the error related to VS Developer Command Prompt. You can switch to x64 Native Tools Command Prompt by the following command,
However, still Boost.Build cannot find vcvarsall.bat. That’s why everything is being skipped for lack of msvc-setup.nup or .bat. Boost.Build expects vcvarsall.bat to exist in the standard MSVC path, because it needs to set environment variables for the toolset. Static linking and b2 itself rely on this.
Your path is quoted incorrectly in combination with b2, and the log shows this:
<p/C:/Users/hechr/source/boost_1_80_0/boost_1_80_0>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\Hostx64\vcvarsall.bat
Notice the concatenation of <p/C:/Users/…> and your MSVC path. Boost treats your path as a literal string, but spaces in Program Files break the batch call.
By switching to the 8.3 DOS short path (C:\PROGRA~1...) in project-config.jam, Boost.Build could finally find and invoke the MSVC compiler. Open Command prompt
for %I in ("C:\Program Files\Microsoft Visual Studio\2022\Community") do @echo %~sI
Then update project-config.jam
C:\Users\hechr\source\boost_1_80_0\boost_1_80_0>cat project-config.jam
# Boost.Build Configuration
# Automatically generated by bootstrap.bat
import option ;
#using msvc : 14.3 : "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.44.35207\\bin\\Hostx64\\x64\\cl.exe" ;
using msvc : 14.3 : "C:\\PROGRA~1\\MICROS~1\\2022\\COMMUN~1\\VC\\Tools\\MSVC\\14.44.35207\\bin\\Hostx64\\x64\\cl.exe";
option.set keep-going : false ;
Then rebuild the project by
b2 toolset=msvc-14.3 address-model=64 link=static runtime-link=static threading=multi --with-regex --with-program_options --with-system --with-filesystem stage