Erlang:“include_lib”和“include_lib”之间有什么区别?和“包括”?
“include_lib”和“include”有什么区别?
例如
-include_lib("eunit/include/eunit.hrl")
What is the difference between "include_lib" and "include" ?
E.g.
-include_lib("eunit/include/eunit.hrl")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档描述 include 和 include_lib 之间的区别的方式是:
因此,在您的示例中,您不需要指出您包含的 eunit 版本,您将包含库路径中存在的 eunit:s 的最新 eunit.hrl 。
The way the documentation describes the difference between include and include_lib is:
So in your example, you dont need to point out the version of eunit that you include, you are including the latest eunit.hrl of the eunit:s that exists in your library path.
一个起初并不明显的区别是
-include
和-include_lib
在查找头文件时使用一组不同的路径。-include_lib
实际上使用的是代码路径,而不是头文件路径。因此,标志
erlc
期望添加到-include
搜索路径的路径是-I
;-include_lib
的标志是-pa
/-pz
。已经提到的事实是,使用
-include_lib
可以让我们免于指定(并因此将模块绑定)到特定的库版本。此外,有一个约定,内部标头存储在项目的
src/
子目录中,并使用-include
包含。 外部标头(供其他库/项目使用)文件存储在include/
中并使用-include_lib
包含。One difference which is not obvious at first is that
-include
and-include_lib
use a different set of paths when looking for header files.-include_lib
in fact uses the code path, not the header file path.Hence, the flag
erlc
expects to add a path to the-include
search path is-I
; the flag for-include_lib
is-pa
/-pz
.Already mentioned is the fact that using
-include_lib
saves us from specifying (and therefore tying) the module to a specific library version.Furthermore, there's a convention that internal headers are stored inside the
src/
subdirectory of a project and included using-include
. External headers (intended to be used by other libraries/projects) files are stored ininclude/
and included using-include_lib
.