如何包含来自 Erlang/OTP 模块的文件

How to include file from Erlang/OTP module

我需要包含一些来自Erlang/OTP模块的头文件,除了使用像

这样的绝对路径之外,还有什么实用的方法吗?

-include("/usr/lib64/erlang/lib/snmp-4.25/include/snmp_types.hrl").

我认为你可以使用:

-include_lib("snmp/include/snmp_types.hrl").

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.

是的,参考问题:Erlang: what is the difference between "include_lib" and "include"?

如果从其系统库中包含,您应该使用 -include_lib(XXX) 而不是 -include(XXX)