简体   繁体   中英

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> :

sudo apt install libboost-dev

According to the Boost install instruction , #include <boost/whatever.hpp> can be achieved using $BOOST_ROOT .

When boost is installed via the repository however $BOOST_ROOT does not exist.

What actually happens when boost is installed from a repository and how to achieve the same outcome when installing from source?

gcc has a default search path. When you compile boost from source and run make install , it installs itself into a directory it refers to as "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.

The boost deb package installs the headers into /usr/include/boost . Since /usr/include is in the gcc header search, no extra work is required.

If you want to replicate that behavior, I suggest you instruct boost to install into /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. This also avoids collisions. Better yet, it is in gcc's default search path for header files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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