在 Windows 上编译 Erlang 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1278959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:59:42  来源:igfitidea点击:

Compiling Erlang code on Windows

windowserlanginstallationcompilation

提问by Niall

I installed Erlang 13B and tried to follow the tutorials.

我安装了 Erlang 13B 并尝试按照教程进行操作。

Every time I get to c(tut), I get an error instead of (ok, tut), so it seems like there are no modules installed. Can anyone point me in the right direction?

每次我到达时c(tut),我都会收到一个错误而不是(ok, tut),所以似乎没有安装模块。任何人都可以指出我正确的方向吗?

I've tried Emacs but I don't really know how to use it and haven't even got close to getting the Erlang mode working. For instance, where do I type:

我已经尝试过 Emacs,但我真的不知道如何使用它,甚至还没有接近让 Erlang 模式工作。例如,我在哪里输入:

  (setq load-path (cons  "C:/Program Files/erl5.6.2/lib/tools-<ToolsVer>/emacs"
    load-path))
  (setq erlang-root-dir "C:/Program Files/erl5.6.2")
  (setq exec-path (cons "C:/Program Files/erl5.6.2/bin" exec-path))
  (require 'erlang-start)

回答by Warren Young

For c(tut)to work, there has to be a tut.erlfile in the current directory.

为了c(tut)工作,tut.erl当前目录中必须有一个文件。

This is easy to accomplish if you start the Erlang interpreter from the command line, as is common on systems like Linux and OS X, but this isn't the usual pattern on Windows. When you start Erlang on Windows from the icon in the Start menu, the current working directory defaults to the location of werl.exe, which isn't where your tut.erlfile is.

如果您从命令行启动 Erlang 解释器,这很容易实现,这在 Linux 和 OS X 等系统上很常见,但这不是 Windows 上的常见模式。当您从开始菜单中的图标启动 Windows 上的 Erlang 时,当前工作目录默认为 的位置werl.exe,这不是您的tut.erl文件所在的位置。

To make your command work as expected, you have to change your working directory to be the location of tut.erlafter starting the Erlang shell. If tut.erlis on the Desktop, the command will be something like this on Vista or Windows 7:

为了使您的命令按预期工作,您必须将工作目录更改为tut.erl启动 Erlang shell 后的位置。如果tut.erl是在桌面上,则命令在 Vista 或 Windows 7 上将是这样的:

cd("c:/Users/myname/Desktop").

(Yes, you have to use forward slashes. Backslashes are special in Erlang strings.)

(是的,您必须使用正斜杠。反斜杠在 Erlang 字符串中很特殊。)

On Windows XP and older, your Desktop folder is buried much deeper. It might be simpler to put werl.exein the system PATHand use the command line on such systems.

在 Windows XP 及更早版本上,您的桌面文件夹被埋得更深。放入werl.exe系统PATH并在此类系统上使用命令行可能更简单。

It isn't necessary, but you might want to consider installing Cygwin. Its Bash shell will give you a more Linux or OS X like environment, which will help you work with other tutorials that are structured for those OSes.

这不是必需的,但您可能需要考虑安装Cygwin。它的 Bash shell 将为您提供更像 Linux 或 OS X 的环境,这将帮助您使用针对这些操作系统构建的其他教程。

回答by Mazen Harake

After you install Erlang open the shell and do:

安装 Erlang 后,打开 shell 并执行以下操作:

1> pwd().
C:/Program Files/erl5.7.1/usr
ok
2>

Assume you have a file; "tut.erl" on your desktop. Content might look like this:

假设你有一个文件;桌面上的“tut.erl”。内容可能如下所示:

-module(tut).
-compile(export_all).

hello_world() ->
  hello.

You must change the path of the current working directory to the desktop first (or where ever you want to do the compile). Like this perhaps:

您必须首先将当前工作目录的路径更改为桌面(或您想要进行编译的任何位置)。大概是这样的:

2> cd("F:/Desktop").
F:/Desktop
ok
3>

Then you can perform the compile.

然后就可以进行编译了。

3> c(tut).
{ok,tut}
4>

Then test the module

然后测试模块

4> tut:hello_world().
hello
5> 

More info refer to the documentation here: Erlang official documentationMore info on the shell, look here: Shell module

更多信息请参阅此处的文档:Erlang 官方文档有关 shell 的更多信息,请参阅此处:Shell 模块

Hope this gets your started.

希望这能让你开始。

回答by detay

You can also create an initialization file named .erlangunder YourErlangInstallationPath\usr\

您还可以创建一个名为.erlang下的初始化文件YourErlangInstallationPath\usr\

the content of the file should look something like this;

文件的内容应该是这样的;

io:format("consulting .erlang in ~p~n" ,
[element(2,file:get_cwd())]).
%% Edit to the directory where you store your code
c:cd("O:/Erlang.Umut").
io:format("Now in:~p~n" , [element(2,file:get_cwd())]).

it will automatically change the path to your working folder. (Obviously, my path is O:/Erlang.Umut, you need to replace it with yours.)

它会自动更改您的工作文件夹的路径。(显然,我的路径是O:/Erlang.Umut,您需要将其替换为您的路径。)

No need to change folders every time you launch console. Console will be able to reach your erl files directly.

每次启动控制台时无需更改文件夹。控制台将能够直接访问您的 erl 文件。

回答by Rrainsmith

I recently tried Erlang on windows.

我最近在 Windows 上尝试了 Erlang。

use the console window to make sure the text editor you are using is giving your files the correct extension ie. filename.erl and not filename.erl.txt like mine was!

使用控制台窗口确保您使用的文本编辑器为您的文件提供了正确的扩展名,即。filename.erl 而不是像我一样的 filename.erl.txt!

when I saved my files in notepad it added .txt so I saved in unicode. fixed

当我将文件保存在记事本中时,它添加了 .txt,因此我以 unicode 保存。固定的

回答by Len

If you are still getting "tut:erl:none: no such file or directory", the file name is wrong. If you open a Windows command prompt and move to your desktop and type "dir" you will see that tut.erl is really named tut.erl.txt. type "ren tut.erl.txt tut.erl" and now your compile will work.

如果您仍然收到“tut:erl:none: no such file or directory”,则文件名是错误的。如果您打开 Windows 命令提示符并移至桌面并键入“dir”,您将看到 tut.erl 真正命名为 tut.erl.txt。输入“ren tut.erl.txt tut.erl”,现在你的编译就可以工作了。

回答by Chawathe Vipul S

When werl's current working directory is same as the file to be compiled, the filename is given as an argument without the whole path. Otherwise, for eg. Assuming tut.erl is placed at C:\ErLang tutorials, one may try compiling as,

当 werl 的当前工作目录与要编译的文件相同时,文件名作为参数给出,没有整个路径。否则,例如。假设 tut.erl 放在 C:\ErLang 教程中,可以尝试编译为,

c("C:\ErLang tutorials\tut").

Note:

笔记:

  1. Without double quotes the : causes syntax error
  2. The backslash is given using escape sequence
  1. 没有双引号的 : 会导致语法错误
  2. 使用转义序列给出反斜杠