Erlang: add libraries to application

2020-04-11 09:59发布

I use erlIDE (based on Eclipse) to work on Erlang projects. Till today everything was fine, but today I have to use external library (couchbeam) in my application. I found out, what is hell, btw.)

The problem is simple – I cannot include external library to compiler path. I've used rebar to get couchbeam's dependencies and it also downloaded ibrowse, mochiweb and ejson.

How can I include those libraries to compiler path without modifing ERL_LIBS to work on project in erlIDE?

I do not want modify ERL_LIBS, because I can change projects's path, start new one (then I should modify ERL_LIBS again) and so on.

I've tried compiler options in erlIDE:

{pa, {pa, 'site_stater/deps/couchbeam/'}}

or

{pa, {pa, '../deps/couchbeam/'}}

where 'site_stater' – is project's name

I wonder how professional erlang programmers organaze their projects workflow (where they write erlang progs, how debuggin it, deal with external libraries and so on).

Many thanks for your attension.

UPDATE I wrote simple function to load libraries, but I think it is still wrong way to deal with this problem:

load_libraries() ->
    ProjectRoot = filename:join([filename:absname("./"), "site_stater"]),
    {ok, DepsList} = file:list_dir(ProjectRoot ++ "/deps/"),
    lists:foreach(fun (Folder) ->
                       RealFolder = ProjectRoot ++ "/deps/" ++ Folder,
                       case filelib:is_dir(RealFolder) of
                           true ->
                               code:add_patha(filename:join([RealFolder, "/ebin"]));
                           false -> ok
                       end
                  end,
                DepsList),
    ok.

标签: erlang
1条回答
虎瘦雄心在
2楼-- · 2020-04-11 10:20

I can't verify it right now, but you should be able to use {pa, '../deps/couchbeam/'} in the compiler options. If that doesn't work, please try using an absolute path.

The compiler settings are not finished yet, we plan to have some simpler way to refer to external libraries but we're not there yet. Every such query from users increases the importance of fixing it!

regards, Vlad

查看更多
登录 后发表回答