Erlang: what is the difference between "include_lib" and "include"?

jldupont picture jldupont · Dec 4, 2009 · Viewed 7.6k times · Source

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

E.g.

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

Answer

Christian picture Christian · Dec 4, 2009

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.