【问题标题】:Cannot find c++ boost header files on Ubuntu 20.04 LTS using apt installation使用 apt 安装在 Ubuntu 20.04 LTS 上找不到 c++ boost 头文件
【发布时间】:2026-02-03 19:30:02
【问题描述】:

我刚刚将我的服务器升级到 ubuntu 20.04 LTS。

我现在正在尝试在上面安装各种不同的代码包,并收到与 boost 安装相关的错误。

我没有从源代码构建,而是使用 apt 安装了 boost 1.71.0:

sudo apt-get install libboost-all-dev

但是,当我尝试编译代码时,我遇到了以下错误:

fatal error: boost/algorithm/string/trim.hpp: No such file or directory
   15 | #include <boost/algorithm/string/trim.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boost/log/sinks/text_ostream_backend.hpp: No such file or directory
    6 | #include <boost/log/sinks/text_ostream_backend.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

过去 3 个小时我一直在尝试查找那些 hpp 文件,但没有成功。里面什么都没有:

/usr/local/include/
/usr/local/lib/
/usr/lib/
/usr/include/boost *doesn't exist*

知道有什么问题吗? 我试图避免从源代码而不是 Ubuntu 软件包安装 boost,但我必须这样做吗?

【问题讨论】:

  • @Ranoiaetep 是的,我已经看到了 *。这指的是默认值/usr/include/boost,但那里什么都没有。另外:locate boost 将 /usr/share/boost-build/ 显示为包含文件的文件夹,但其中仅包含大量 .jam 文件。我没有找到任何 .hpp 文件。
  • sudo apt-get install libboost-all-dev 成功了吗?再试一次,看看输出消息。
  • @prehistoricpenguin 我已经做了很多安装。 sudo apt-get install libboost-all-dev Reading package lists... Done Building dependency tree Reading state information... Done libboost-all-dev is already the newest version (1.71.0.0ubuntu2). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 但我也使用过 removeinstall 甚至 reinstall

标签: c++ ubuntu boost ubuntu-20.04


【解决方案1】:

设法解决了问题。

事实证明,因为我之前通过手动安装(在升级到 20.04 LTS 之前)进行了 boost 安装并且手动删除了这些文件,因此通过 apt 进一步重新安装并没有重新创建 usr/include/ 中的文件,因为其他与 boost 相关的软件包仍然安装在系统中。

恢复是运行apt list --installed '*boost*',然后卸载任何这些链接包。 之后,运行sudo apt install libboost-all-dev 重新创建了包含所有头文件的 /usr/include/boost 目录。

此过程已列在答案中:https://askubuntu.com/questions/1161393/i-deleted-usr-include-boost-installing-libboost-all-dev-wont-bring-headers-ba

【讨论】: