简体   繁体   English

如何从源代码中实现从存储库安装boost的相同结果?

[英]How to achieve the same result installing boost from source as from a repository?

When boost is installed using the below code it can be simply included in a project using #include <boost/whatever.hpp> : 使用以下代码安装boost时,可以使用#include <boost/whatever.hpp>将其简单地包含在项目中:

sudo apt install libboost-dev

According to the Boost install instruction , #include <boost/whatever.hpp> can be achieved using $BOOST_ROOT . 根据Boost安装指令 ,可以使用$BOOST_ROOT实现#include <boost/whatever.hpp>

When boost is installed via the repository however $BOOST_ROOT does not exist. 通过存储库安装boost但是$BOOST_ROOT不存在。

What actually happens when boost is installed from a repository and how to achieve the same outcome when installing from source? 从存储库安装boost时实际发生了什么,以及从源安装时如何实现相同的结果?

gcc has a default search path. gcc有一个默认的搜索路径。 When you compile boost from source and run make install , it installs itself into a directory it refers to as "BOOST_ROOT". 当您从源代码编译boost并运行make install ,它会将自身安装到一个名为“BOOST_ROOT”的目录中。 Since that directory isn't in gcc's default search path for include files, you have to go some extra mile in order for program to find the headers when you compile. 由于该目录不在gcc的包含文件的默认搜索路径中,因此您必须加倍努力才能使程序在编译时找到标题。

The boost deb package installs the headers into /usr/include/boost . boost deb软件包将头文件安装到/usr/include/boost Since /usr/include is in the gcc header search, no extra work is required. 由于/usr/include是在gcc头文件搜索中,因此不需要额外的工作。

If you want to replicate that behavior, I suggest you instruct boost to install into /usr/local/include/boost . 如果您想复制该行为,我建议您指示boost安装到/usr/local/include/boost

The /usr/local directories are dedicated to installation of locally compiled libraries, so it is a better path than /usr/include , where the deb installs. /usr/local目录专用于安装本地编译的库,因此它比deb安装的/usr/include更好。 This also avoids collisions. 这也避免了碰撞。 Better yet, it is in gcc's default search path for header files. 更好的是,它是gcc默认的头文件搜索路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM