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

前端 未结 2 1026
醉酒成梦
醉酒成梦 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:25

    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.

提交回复
热议问题