Erlang: what is the difference between “include_lib” and “include”?

前端 未结 2 1031
醉酒成梦
醉酒成梦 2020-12-13 18:15

What is the difference between \"include_lib\" and \"include\" ?

E.g.

-include_lib(\"eunit/include/eunit.hrl\")

2条回答
  •  孤街浪徒
    2020-12-13 18:32

    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.

提交回复
热议问题