Erlang:“include_lib”和“include_lib”之间有什么区别?和“包括”?

发布于 2024-08-13 07:07:35 字数 108 浏览 1 评论 0原文

“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦醒时光 2024-08-20 07:07:35

文档描述 include 和 include_lib 之间的区别的方式是:

include_libinclude 类似,但不应指出绝对文件。相反,第一个路径组件(可能在变量替换之后)被假定为应用程序的名称。

示例:

-include_lib("kernel/include/file.hrl")。

代码服务器使用code:lib_dir(kernel)查找当前(最新)版本Kernel的目录,然后在子目录include中查找文件file.hrl。

因此,在您的示例中,您不需要指出您包含的 eunit 版本,您将包含库路径中存在的 eunit:s 的最新 eunit.hrl 。

The way the documentation describes the difference between include and include_lib is:

include_lib is similar to include, but should not point out an absolute file. Instead, the first path component (possibly after variable substitution) is assumed to be the name of an application.

Example:

-include_lib("kernel/include/file.hrl").

The code server uses code:lib_dir(kernel) to find the directory of the current (latest) version of Kernel, and then the subdirectory include is searched for the file file.hrl.

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.

权谋诡计 2024-08-20 07:07:35

一个起初并不明显的区别是 -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 in include/ and included using -include_lib.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文