Boost编译笔记
Boost 1.89.0编译(mpi异常修复)

Boost官网:
环境:vs2022
p.s. 1.83.0编译不通过,所以选了1.89.0版本继续
通过x64 Native Tools Command Prompt for VS 2022进入环境。

:: 进入源码解压后的目录
cd /d xxx\boost_1_89_0
:: 生成b2.exe
bootstrap.bat
:: 编译命令
b2 --without-test --without-python toolset=msvc address-model=64 variant=release link=shared runtime-link=shared threading=multi stage
:: 安装命令
b2 --without-test --without-python toolset=msvc address-model=64 variant=release link=shared runtime-link=shared threading=multi --prefix=install install
- 编译log,发现大部分模块编译通过,一个模块mpi出现异常error:
error: No best alternative for /F:/dev-tool/libs/boost_1_89_0/libs/mpi/build/boost_mpi with <abi>ms <address-model>64 <architecture>x86 <asynch-exceptions>off <binary-format>pe <boost.beast.allow-deprecated>on <boost.beast.separate-compilation>on <boost.cobalt.executor>any_io_executor <boost.cobalt.pmr>std <context-impl>fcontext <coverage>off <debug-store>object <debug-symbols>off <embed-manifest-via>linker <embed-manifest>on <exception-handling>on <extern-c-nothrow>off <inlining>full <known-warnings>hide <link>shared <midl-robust>yes <midl-stubless-proxy>yes <optimization>speed <os>NT <pch>on <preserve-test-targets>on <profiling>off <python-debugging>off <rtti>on <runtime-debugging>off <runtime-link>shared <stdlib>native <strip>off <target-os>windows <testing.execute>on <threadapi>win32 <threading>multi <toolset-msvc:version>14.3 <toolset>msvc <variant>release <vectorize>off <visibility>hidden <warnings-as-errors>off <warnings>on <windows-api>desktop <x-deduced-platform>x86_64
matched: (empty)
matched: (empty)
- 查找boost mpi的可用MPI,网页提到了可用的MPI库:
- Open MPI
- MPICH2
- Intel MPI
然而,豆包这货给我推荐MS-MPI,我就试试吧。
尝试使用MS-MPI修复MPI编译错误
:: 设置环境变量
set MSMPI_INC=C:\Program Files (x86)\Microsoft SDKs\MPI\Include
set MSMPI_LIB=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64
:: 编译脚本
b2 -j8 toolset=msvc address-model=64 link=shared runtime-link=shared variant=release threading=multi --with-mpi mpi-include="%MSMPI_INC%" mpi-libpath="%MSMPI_LIB%"
- 异常
error: unknown feature "<mpi-include>"
F:/dev-tool/libs/boost_1_89_0/tools/build/src/build\feature.jam:361: in expand-subfeatures-aux from module feature
F:/dev-tool/libs/boost_1_89_0/tools/build/src/build\feature.jam:422: in feature.expand-subfeatures from module feature
F:/dev-tool/libs/boost_1_89_0/tools/build/src/build\build-request.jam:20: in apply-to-property-set from module build-request
(builtin):-1: in sequence.transform from module sequence
F:/dev-tool/libs/boost_1_89_0/tools/build/src/build\build-request.jam:32: in build-request.expand-no-defaults from module build-request
F:/dev-tool/libs/boost_1_89_0/tools/build/src\build-system.jam:808: in module scope from module build-system
- 尝试修复
在cnblogs上有一篇博客提及了Boost MPI在window中的配置问题,根目录:project-config.jam加入
using mpi ;
- 尝试编译
b2 -j8 toolset=msvc address-model=64 link=shared runtime-link=shared variant=release threading=multi --with-mpi
- 异常
...failed compile-c-c++ bin.v2\libs\mpi\build\msvc-14.3\release\x86_64\threading-multi\content_oarchive.obj...
compile-c-c++ bin.v2\libs\mpi\build\msvc-14.3\release\x86_64\threading-multi\mpi_datatype_cache.obj
mpi_datatype_cache.cpp
.\boost/mpi/exception.hpp(86): warning C4251: “boost::mpi::exception::message”:“std::basic_string<char,std::char_traits<char>,std::allocator<char>>”需要有 dll 接口以供“boost::mpi::exception”的客户端使用
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\xstring(541): note: 参见“std::basic_string<char,std::char_traits<char>,std::allocator<char>>”的声明
.\boost/mpi/exception.hpp(33): warning C4275: 非 dll 接口 class“std::exception”用作 dll 接口 class“boost::mpi::exception”的基
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\vcruntime_exception.h(49): note: 参见“std::exception”的声明
.\boost/mpi/exception.hpp(33): note: 参见“boost::mpi::exception”的声明
.\boost/mpi/detail/mpi_datatype_primitive.hpp(62): warning C4267: “参数”: 从“size_t”转换到“int”,可能丢失数据
.\boost/mpi/detail/mpi_datatype_primitive.hpp(81): warning C4267: “参数”: 从“size_t”转换到“int”,可能丢失数据
.\boost/mpi/detail/mpi_datatype_cache.hpp(49): warning C4275: 非 dll 接口 class“boost::noncopyable_::noncopyable”用作 dll 接口 class“boost::mpi::detail::mpi_datatype_map”的基
.\boost/core/noncopyable.hpp(38): note: 参见“boost::noncopyable_::noncopyable”的声明
.\boost/mpi/detail/mpi_datatype_cache.hpp(48): note: 参见“boost::mpi::detail::mpi_datatype_map”的声明
.\boost/mpi/datatype.hpp(217): error C2065: “MPI_CXX_BOOL”: 未声明的标识符
call "bin.v2\standalone\msvc\msvc-14.3\msvc-setup.bat" >nul
cl /Zm800 -nologo "F:\dev-tool\libs\boost_1_89_0\libs\mpi\src\mpi_datatype_cache.cpp" -c -Fo"bin.v2\libs\mpi\build\msvc-14.3\release\x86_64\threading-multi\mpi_datatype_cache.obj" -TP /wd4675 /EHs /GR /Zc:throwingNew /O2 /Ob2 /W3 /MD /Zc:forScope /Zc:wchar_t /Zc:inline /Gw /favor:blend -DBOOST_ALL_NO_LIB=1 -DBOOST_COBALT_USE_STD_PMR=1 -DBOOST_CONTAINER_DYN_LINK=1 -DBOOST_CONTAINER_NO_LIB=1 -DBOOST_MPI_DYN_LINK=1 -DBOOST_MPI_SOURCE=1 -DNDEBUG -D_SECURE_SCL=0 "-I." "-IC:\Program Files (x86)\Microsoft SDKs\MPI\Include" "-IF:\dev-tool\libs\boost_1_89_0\libs\assert\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\bind\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\concept_check\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\container\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\core\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\detail\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\function\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\integer\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\intrusive\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\iterator\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\lexical_cast\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\move\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\mpi\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\mpl\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\optional\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\predef\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\preprocessor\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\smart_ptr\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\static_assert\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\throw_exception\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\type_traits\include" "-IF:\dev-tool\libs\boost_1_89_0\libs\utility\include" "-Ilibs\config\include"
显然MS-MPI不太友好,扒了巨硬的MPI官网以及github仓库发现这货的最新发行版还是2019年的,boost这是比较近期的,极大不兼容,果断弃坑。
尝试使用intel MPI修复MPI编译错误
MS-MPI太老了,使用intel MPI,修改根目录project-config.jam
- intel mpi下载页面
- intel-mpi-2021.18.0.742_offline
- 继续修改project-config.jam
using mpi
: "C:/Program Files (x86)/Intel/oneAPI/mpi/2021.18/bin/mpicxx.exe"
:
<include>"C:/Program Files (x86)/Intel/oneAPI/mpi/2021.18/include"
<library-path>"C:/Program Files (x86)/Intel/oneAPI/mpi/2021.18/lib"
<find-static-library>impi
;
- 编译
:: 仅编译mpi模块
b2 -j8 toolset=msvc address-model=64 link=shared runtime-link=shared variant=release threading=multi --with-mpi
:: 如果没有异常出现,说明mpi编译异常已修复,采用全量编译
b2 --without-test --without-python -j4 toolset=msvc address-model=64 variant=release link=shared runtime-link=shared threading=multi stage
:: 编译完成后安装到目录[install],但是根目录有个INSTALL文件,需要先将其修改成INSTALL_,否则安装失败
b2 --without-test --without-python -j4 toolset=msvc address-model=64 variant=release link=shared runtime-link=shared threading=multi --prefix=install install
- 完全编译的dll
cd install/lib
dir /b *.dll
boost_atomic-vc143-mt-x64-1_89.dll
boost_charconv-vc143-mt-x64-1_89.dll
boost_chrono-vc143-mt-x64-1_89.dll
boost_container-vc143-mt-x64-1_89.dll
boost_context-vc143-mt-x64-1_89.dll
boost_contract-vc143-mt-x64-1_89.dll
boost_coroutine-vc143-mt-x64-1_89.dll
boost_date_time-vc143-mt-x64-1_89.dll
boost_fiber-vc143-mt-x64-1_89.dll
boost_filesystem-vc143-mt-x64-1_89.dll
boost_graph-vc143-mt-x64-1_89.dll
boost_graph_parallel-vc143-mt-x64-1_89.dll
boost_iostreams-vc143-mt-x64-1_89.dll
boost_json-vc143-mt-x64-1_89.dll
boost_locale-vc143-mt-x64-1_89.dll
boost_log-vc143-mt-x64-1_89.dll
boost_log_setup-vc143-mt-x64-1_89.dll
boost_math_c99-vc143-mt-x64-1_89.dll
boost_math_c99f-vc143-mt-x64-1_89.dll
boost_math_c99l-vc143-mt-x64-1_89.dll
boost_math_tr1-vc143-mt-x64-1_89.dll
boost_math_tr1f-vc143-mt-x64-1_89.dll
boost_math_tr1l-vc143-mt-x64-1_89.dll
boost_mpi-vc143-mt-x64-1_89.dll
boost_nowide-vc143-mt-x64-1_89.dll
boost_process-vc143-mt-x64-1_89.dll
boost_program_options-vc143-mt-x64-1_89.dll
boost_random-vc143-mt-x64-1_89.dll
boost_regex-vc143-mt-x64-1_89.dll
boost_serialization-vc143-mt-x64-1_89.dll
boost_stacktrace_from_exception-vc143-mt-x64-1_89.dll
boost_stacktrace_noop-vc143-mt-x64-1_89.dll
boost_stacktrace_windbg-vc143-mt-x64-1_89.dll
boost_stacktrace_windbg_cached-vc143-mt-x64-1_89.dll
boost_thread-vc143-mt-x64-1_89.dll
boost_timer-vc143-mt-x64-1_89.dll
boost_type_erasure-vc143-mt-x64-1_89.dll
boost_url-vc143-mt-x64-1_89.dll
boost_wave-vc143-mt-x64-1_89.dll
boost_wserialization-vc143-mt-x64-1_89.dll
- 完整的project-config.jam
# Boost.Build Configuration
# Automatically generated by bootstrap.bat
import option ;
using msvc ;
# using mpi ;
using mpi
: "C:/Program Files (x86)/Intel/oneAPI/mpi/2021.18/bin/mpicxx.exe"
:
<include>"C:/Program Files (x86)/Intel/oneAPI/mpi/2021.18/include"
<library-path>"C:/Program Files (x86)/Intel/oneAPI/mpi/2021.18/lib"
<find-static-library>impi
;
option.set keep-going : false ;
终于把boost编译完全了,后面使用起来就比较方便了。
boost 1.85.0编译(无法找到编译器)
编译环境:最新vs2022社区版
异常情况
采用vs2022社区版本,可以运行bootstrap.bat生成b2.exe,但是执行以下命令时出现问题:
b2 address-model=64 variant=release link=shared runtime-link=shared threading=multi --without-python --without-test -j4 stage
- 找不到编译器
Performing configuration checks
- default address-model : none [1]
- default architecture : none [1]
- x86 : no [2]
- arm : no [2]
- mips1 : no [2]
- power : no [2]
- sparc : no [2]
- cxx11_static_assert : no [2]
- x86 : no [3]
- arm : no [3]
- mips1 : no [3]
- power : no [3]
- sparc : no [3]
- cxx11_static_assert : no [3]
- cxx11_variadic_templates : no [2]
- cxx11_variadic_templates : no [3]
- cxx11_hdr_ratio : no [2]
- cxx11_hdr_ratio : no [3]
- cxx20_hdr_concepts : no [2]
- cxx20_hdr_concepts : no [3]
解决办法
-
参考以下2篇博客可以知道,vs2022的版本太新了b2不认识,那只能人工指定了。
https://blog.csdn.net/ljjjjjjjjjjj/article/details/122312270
https://www.cnblogs.com/PeterZ1997/p/18548222 -
确定msvc版本,打开
x64 Native Tools Command Prompt for VS 2022的时候,使用PATH命令查看环境变量,会找到类似:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64
- 修改根目录的project-config.jam文件,指定msvc的版本及路径。
# Boost.Build Configuration
# Automatically generated by bootstrap.bat
import option ;
using msvc : 14.44 : "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX64\\x64\\cl.exe";
option.set keep-going : false ;
- 采用指定版本的工具
:: 编译
b2 toolset=msvc-14.44 address-model=64 variant=release link=shared runtime-link=shared threading=multi --without-python --without-test -j4 stage
:: 安装在install,请确认根目录的INSTALL文件修改为其它名字,避免冲突造成安装失败。
b2 toolset=msvc-14.44 address-model=64 variant=release link=shared runtime-link=shared threading=multi --without-python --without-test -j4 --prefix=install install
VS版本对应工具链、宏关系

Location
- 1)2026.5.16 于广东佛山市禅城区季华路附近
- 2)2026.5.17 于广东佛山市禅城区魁奇路附近

浙公网安备 33010602011771号