踩坑记录:因版本不匹配导致 Boost 1.85 编译失败的完整解决过程

踩坑记录:因版本不匹配导致 Boost 1.85 编译失败的完整解决过程

转载请注明出处,欢迎评论区交流。

背景

最近在 Windows 11 + VS2022 环境下尝试用 b2 编译 Boost 1.85.0,结果一路踩坑,最后发现罪魁祸首是 Boost.Build 自带的 msvc.jam 对 VS 17.10(14.4)识别不完整

官方 issue #931 里也提到了同样的报错,但没有一个完整的解决流程,于是把今天的填坑过程记录下来,希望能帮到后来者。


现象

执行:

bash 复制代码
bootstrap.bat
b2 toolset=msvc-14.4 variant=release

很快报错退出,关键信息:

复制代码
...patience...
...found 1891 targets...
...updating 4 targets...
msvc.write-setup-script
bin.v2\tools\build\src\engine\msvc-setup.bat
The system cannot find the path specified.

随后 b2 直接退出,返回码 1。用 --debug-configuration 再跑一次,发现 msvc.jam 里这一段:

jam 复制代码
if [ MATCH "(14.4)" : $(version) ]
{
    parent = [ path.native [ path.join $(parent) "..\..\..\..\..\Auxiliary\Build" ] ] ;
}

并没有被执行,也就是说 Boost.Build 根本没把 14.4 当成合法版本,于是 vcvarsall.bat 的路径就拼错,导致找不到编译环境。


根因分析

  1. Boost.Build 1.85 的 msvc.jam 只识别到 14.3

    用文本编辑器打开
    boost_1_85_0\tools\build\src\tools\msvc.jam

    搜索 14.3 能看到对应的 if 分支,但 没有 14.4

  2. **VS2022 17.10 的 _MSC_VER = 1940**, 对应 14.4` 工具集,Boost.Build 不认识,于是 fallback 失败。


解决方案(任选其一)

✅ 方案 A:官方补丁文件直接替换(推荐)

  1. 下载官方提供的 msvc.zip

  2. 关闭所有占用 boost_1_85_0\tools\build\src\tools\msvc.jam 的编辑器/IDE。

  3. 把压缩包里的 msvc.jam 覆盖到
    boost_1_85_0\tools\build\src\tools\msvc.jam

  4. 重新执行:

    bash 复制代码
    b2 toolset=msvc-14.4 -j8
  5. 编译顺利通过。

✅ 方案 B:手动打补丁(不想覆盖文件时)

msvc.jamelse if [ MATCH "(14.3)" : $(version) ] 后面追加:

jam 复制代码
else if [ MATCH "(14.4)" : $(version) ]
{
    if $(.debug-configuration)
    {
        ECHO "notice: [generate-setup-cmd] $(version) is 14.4" ;
    }
    parent = [ path.native [ path.join $(parent) "..\..\..\..\..\Auxiliary\Build" ] ] ;
}

保存后重新 b2 即可。


验证

bash 复制代码
>b2 --version
B2 4.10.1 (OS=NT, jobs=8)

>b2 toolset=msvc-14.4 address-model=64 architecture=x86 variant=release --with-system --with-filesystem
...found 2037 targets...
...updating 18 targets...
...updated 18 targets...

输出无报错,生成的 .lib.dll 也正常。


小结

  • Boost 1.85 尚未完全适配 VS2022 17.10,但社区补丁已经可用。
  • 如果后续 VS 再升级,大概率还会遇到同样问题,直接照葫芦画瓢在 msvc.jam 里加一行即可。
  • 建议把补丁文件存一份到私有仓库,CI/CD 里自动打补丁,避免每次手动操作。

参考资料


相关推荐
卡戎-caryon3 个月前
【项目实践】boost 搜索引擎
linux·前端·网络·搜索引擎·boost·jieba·cpp-http
GOTXX4 个月前
BoostSiteSeeker项目实战
前端·c++·后端·mysql·搜索引擎·项目实战·boost
云梦谭5 个月前
boost::beast websocket 实例
websocket·boost
码农客栈7 个月前
ARM交叉编译Boost库
boost
易板7 个月前
微源SOT23-6封装LED背光驱动LP3302
boost·led驱动·背光驱动
过过过呀Glik7 个月前
在 Ubuntu 上安装 Muduo 网络库的详细指南
linux·c++·ubuntu·boost·muduo
mixboot7 个月前
filecoin boost GraphQL API 查询
graphql·boost
雪域迷影9 个月前
Ubuntu22.04中使用CMake配置运行boost库示例程序
linux·c++·boost·ubuntu22.04
SunkingYang1 年前
boost库容器之Circular Buffer功能介绍,及使用示例
c++·boost·用例·circular buffer·循环缓冲区·功能介绍