Erlang:如何包括图书馆 [英] Erlang: How to include libraries

查看:149
本文介绍了Erlang:如何包括图书馆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的Erlang程序,请求一个URL并将其作为JSON解析。



为此,我需要使用一个名为Jiffy的库。我下载并编译它,现在我有一个.beam文件以及.app文件。我的问题是:我该怎么用?如何在我的程序中加入这个库?我不明白为什么我不能在网上找到一个必须非常关键的答案。



Erlang有一个包含语法,但是收到一个.hrl文件。



谢谢!

解决方案

您不需要文件在你的项目。在Erlang中,在运行时,代码将尝试找到任何函数。因此,您正在使用的模块必须位于VM所在的运行代码的搜索路径中,这就是所有。



为此,您可以添加文件当您启动erlang时,您的路径:erl -pa your / path / to / beam(它也存在-pz请参阅 erlang doc



请注意,也可以使用代码:add_path(Dir)从应用程序本身修改路径。 p>

您应该看看OTP方式在erlang文档中构建应用程序,或者了解一些Erlang ,还可以查看Rebar一个工具,帮助您管理erlang应用程序(例如从钢筋开始钢筋维基


I'm writing a simple Erlang program that requests an URL and parses the response as JSON.

To do that, I need to use a Library called Jiffy. I downloaded and compiled it, and now i have a .beam file along with a .app file. My question is: How do I use it? How do I include this library in my program?. I cannot understand why I can't find an answer on the web for something that must be very crucial.

Erlang has an include syntax, but receives a .hrl file.

Thanks!

解决方案

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)

这篇关于Erlang:如何包括图书馆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆