【问题标题】:Compiling Erlang module using erl.exe使用 erl.exe 编译 Erlang 模块
【发布时间】:2013-04-08 02:32:38
【问题描述】:

我对 Erlang 非常陌生,我正在尝试编译我的第一个 Erlang 模块,并收到一个错误,即不存在这样的文件,尽管它确实存在。

非常感谢任何关于我 erl.exe 无法编译 useless.erl 的建议。

非常感谢!

erl.exe 命令提示符(注意模块实际上包含 useless.erl)

1> filename:absname("C:/Users/modules"). 
"C:/Users/modules"
2> c(useless). 
useless.erl:none: no such file or directory

(无用的.erl)

-module(useless).
-export([add/2, hello/0, greet_and_add_two/1]).

add(A,B) ->
A + B.

%% Shows greetings.
%% io:format/1 is the standard function used to output text.
hello() ->
io:format("Hello, world!~n").

greet_and_add_two(X) ->
hello(),
add(X,2).

【问题讨论】:

  • 你是如何创建useless.erl的?某些 Windows 编辑器是“文本”编辑器,会自动将 .txt 附加到文件 nane。因此,在您的情况下,该文件实际上将被命名为 useless.erl.txt erlang 找不到。
  • 感谢您的回复。不,useless 仅以 .erl 结尾,并且上面有一个 erlang 图标,没有 .txt 扩展名。
  • filename:absname/1 实际上并没有更改目录。我想你需要cd("c:/users/modules").
  • 是的,当然。我也应该看到的。
  • @Shane Charles,感谢您的回复!这适用于更改目录。但是,我目前在编译时遇到错误:useless.bea#: error writing file

标签: compilation erlang erlang-shell


【解决方案1】:

使用该表单,您需要在与您尝试编译的模块相同的目录中执行erl。使用c 函数时可以指定文件路径。这将在您的当前目录中创建一个.beam 文件:

Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V5.10.1  (abort with ^G)
1> c("stackoverflow/passfun.erl").
{ok,passfun}
2> passfun:some_func().
hello

【讨论】:

  • 感谢您的回复。这对我不起作用。我无法执行c 命令。我收到以下错误useless.bea#: error writing file
  • 你在哪里运行erl?您可能没有写入当前目录的权限。
  • +1,谢谢!权限实际上是问题所在,一旦我以管理员身份运行 erl.exe,一切运行良好。
猜你喜欢
  • 1970-01-01
  • 2018-06-14
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-27
  • 1970-01-01
  • 2018-03-29
相关资源
最近更新 更多