c++ - 如何从源代码安装 boost 获得与从存储库安装 boost 相同的结果?

标签 c++ linux ubuntu boost installation

当使用以下代码安装 boost 时,可以使用 #include <boost/whatever.hpp> 将其简单地包含在项目中:

sudo apt install libboost-dev

根据Boost install instruction , #include <boost/whatever.hpp>可以使用 $BOOST_ROOT 来实现.

然而,当通过存储库安装 boost 时 $BOOST_ROOT不存在。

从存储库安装 boost 时实际发生了什么?从源代码安装时如何实现相同的结果?

最佳答案

gcc 有一个默认的搜索路径。当您从源代码编译 boost 并运行 make install 时,它会将自己安装到一个它称为“BOOST_ROOT”的目录中。由于该目录不在 gcc 的默认包含文件搜索路径中,因此您必须多做一些工作才能让程序在编译时找到 header 。

boost deb 包将 header 安装到 /usr/include/boost 中。由于 /usr/include 在 gcc header 搜索中,因此不需要额外的工作。

如果您想复制该行为,我建议您指示 boost 安装到 /usr/local/include/boost

/usr/local 目录专用于安装本地编译的库,因此它是比安装 deb 的 /usr/include 更好的路径。这也避免了碰撞。更好的是,它位于 gcc 的默认头文件搜索路径中。

关于c++ - 如何从源代码安装 boost 获得与从存储库安装 boost 相同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46397733/

相关文章:

c++ - 在 emacs 中将 .h 设置为 c++ 模式组

python - Kivy 不工作,MESA-LOADER : failed to open iris and swrast

linux - Linux下Eclipse在哪里找eclipse.ini

linux - 无法删除设备/dev/loop0

c++ - 使用OpenCV创建视频-Gstreamer编解码器不起作用

c# - 对 PInvoke 函数 [函数名称] 的调用使堆栈不平衡

c++ - 使用 time() 函数计算执行时间

android - android内核编译错误

linux - 是否有支持大多数 VS Visual C++ 的 Linux Visual C++ 编译器?

javascript - 用 javascript 编写的 FD_SET 和 FD_ISSET 宏