[英]use “-I” to define g++ include path:why it only works when I set “…/include” instead of “…/include/boost”?
My application need boost lib.我的应用程序需要提升库。 There is a boost lib in /usr/lib and boost include in /usr/include/boost, but they aren's what I need. /usr/lib 中有一个 boost 库,/usr/include/boost 中有一个 boost 包含,但它们正是我所需要的。 So I compile new boost lib in my home, /home/js/anaconda/.../include/boost and /home/js/anaconda/.../lib.所以我在家里编译了新的 boost lib,/home/js/anaconda/.../include/boost 和 /home/js/anaconda/.../lib。
To use boost in home, I use "-I/home/js/anaconda/.../include/boost" to define the include path, however, It complain error because it find boost in the "/usr/..." path.要在家中使用 boost,我使用“-I/home/js/anaconda/.../include/boost”来定义包含路径,但是,它抱怨错误,因为它在“/usr/... “ 小路。 Then I try use "-I/home/js/anaconda/.../include" (the parent directory) and it works fine!然后我尝试使用“-I/home/js/anaconda/.../include”(父目录),它工作正常!
My question is 1)why it works when I specify the parent directory "/home/.../include" instead of "/home/.../include/boost"?我的问题是 1)为什么当我指定父目录“/home/.../include”而不是“/home/.../include/boost”时它会起作用? what is the right directory I should specify when I use "-I"?使用“-I”时应该指定的正确目录是什么?
2)when I use "-I" to specify some directory, will these directory always be the one prior to the /usr directory? 2)当我使用“-I”指定某个目录时,这些目录是否总是在 /usr 目录之前的目录?
It's a common practice (but not mandatory) to include all the header files of a library into its own directory.将库的所有 header 文件包含到其自己的目录中是一种常见做法(但不是强制性的)。 This has a few advantages:这有几个优点:
When you use -I
preprocessor flag to add a directory to the include search path, that directory can either:当您使用-I
预处理器标志将目录添加到包含搜索路径时,该目录可以:
include
following the filesystem hierarchy standard .这些目录的路径以include
结尾,遵循文件系统层次标准。 In the particular case of boost, the intended use is to -I/path-to-boost-install/include
flag and then use an include directive such as #include <boost/optional/optional.hpp>
to use one of the libraries in that installation.在 boost 的特定情况下,预期用途是使用-I/path-to-boost-install/include
标志,然后使用诸如#include <boost/optional/optional.hpp>
之类的包含指令来使用其中一个库在那个安装中。
The best advice is to read the documentation and look for examples before you start using a library.最好的建议是在开始使用库之前阅读文档并查找示例。 In the case of boost, you can read the getting started on Unix or getting started on Windows pages:对于 boost,您可以阅读Unix 上的入门或Windows 页面上的入门:
It's important to note the following:请务必注意以下几点:
The path to the boost root directory (often /usr/local/boost_1_75_0) is sometimes referred to as $BOOST_ROOT in documentation and mailing lists. boost 根目录的路径(通常是 /usr/local/boost_1_75_0)在文档和邮件列表中有时称为 $BOOST_ROOT。
To compile anything in Boost, you need a directory containing the boost/ subdirectory in your #include path.要在 Boost 中编译任何东西,您需要一个目录,该目录在您的 #include 路径中包含boost/ 子目录。
Since all of Boost's header files have the.hpp extension, and live in the boost/ subdirectory of the boost root, your Boost #include directives will look like:由于 Boost 的所有 header 文件都具有 .hpp 扩展名,并且位于 boost 根目录的 boost/ 子目录中,因此您的 Boost #include 指令将如下所示:
#include <boost/whatever.hpp>
or或者
#include "boost/whatever.hpp"
depending on your preference regarding the use of angle bracket includes.取决于您对使用尖括号的偏好,包括。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.