Erlang: How to include libraries

一曲冷凌霜 提交于 2019-12-05 18:44:27

You don't need to include the file in your project. In Erlang, it is at run time that the code will try to find any function. So the module you are using must be in the search path of the VM which run your code at the point you need it, that's all.

For this you can add files to your path when you start erlang: erl -pa your/path/to/beam (it exists also -pz see erlang doc)

Note that it is also possible to modify the path from the application itself using code:add_path(Dir).

You should have a look to the OTP way to build applications in erlang documentation or Learn You Some Erlang, and also look at Rebar a tool that helps you to manage erlang application (for example starting with rebar or rebar wiki)

To add to Pascal's answer, yes Erlang will search for your files at runtime and you can add extra paths as command line arguments.

However, when you build a project of a scale that you are including other libraries, you should be building an Erlang application. This normally entails using rebar.

When using rebar, your app should have a deps/ directory. To include jiffy in your project, it is easiest to simply clone the repo into deps/jiffy. That is all that needs to be done for you to do something like jiffy:decode(Data) in your project.

Additionally, you can specify additional include files in your rebar.config file by adding extra lines {erl_opts, [{i, "./Some/path/to/file"}]}.. rebar will then look for file.so using that path.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!