首页 > 解决方案 > 为导入的模块生成 .beam 文件

问题描述

我正在学习 erlnag,对“.beam”文件的创建有一点疑问。例如,我有 helloworld.erl 和 top.erl 文件,并且 helloworld.erl 被导入到 top.erl 中。

顶部.erl:

-module(top).
-import(helloworld, [start/0]).
-export([main/0]).

main() ->
  io:fwrite("hello\n"),
  start().

helloworld.erl

-module(helloworld).
-export([start/0]).

start() ->
  io:fwrite("hello world\n").

然后使用“erlc top.erl”编译top.erl。然后,它只创建top.beam文件,而不是创建helloworld.beam文件。

但是当我们看到在python和java的情况下,在编译导入文件时也会为导入的文件生成目标文件。

这是'erlang'的行为(即不为导入的文件创建.beam文件)还是我理解错了?

(或者)

请解释在运行导入模块时获取导入文件的“.beam”文件的过程。

谢谢..

标签: erlang

解决方案


erlc只编译你要求它编译的文件。您可以使用以下命令编译当前目录中的所有文件:

erlc *.erl

您可能想要使用工具来构建您的项目。内置的一个选项是模块make不要与make命令行工具混淆)。您可以使用以下命令运行它:

erl -make

它会在当前目录中查找名为Emakefilefile 的配置文件,但如果没有,它只会编译目录中的所有源文件。

其他替代品是rebar3erlang.mk


推荐阅读