简体   繁体   English

在Windows上编译Erlang代码

[英]Compiling Erlang code on Windows

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. 每次我到c(tut) ,我得到一个错误而不是(ok, tut) ,所以似乎没有安装模块。 Can anyone point me in the right direction? 谁能指出我正确的方向?

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. 我已经尝试过Emacs,但我真的不知道如何使用它,甚至没有接近让Erlang模式工作。 For instance, where do I type: 例如,我在哪里输入:

  (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)

For c(tut) to work, there has to be a tut.erl file 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. 如果从命令行启动Erlang解释器,这很容易实现,这在Linux和OS X等系统上很常见,但这不是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.erl file is. 当您从“开始”菜单中的图标启动Windows上的Erlang时,当前工作目录默认为werl.exe的位置,而该位置不是您的tut.erl文件所在的tut.erl

To make your command work as expected, you have to change your working directory to be the location of tut.erl after starting the Erlang shell. 要使命令按预期工作,必须在启动Erlang shell后将工作目录更改为tut.erl的位置。 If tut.erl is on the Desktop, the command will be something like this on Vista or Windows 7: 如果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. 在Windows XP及更早版本中,您的桌面文件夹更深层次。 It might be simpler to put werl.exe in the system PATH and use the command line on such systems. werl.exe放入系统PATH并在此类系统上使用命令行可能更简单。

It isn't necessary, but you might want to consider installing Cygwin . 没有必要,但您可能需要考虑安装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. 它的Bash shell将为您提供更多Linux或OS X环境,这将帮助您使用为这些操作系统构建的其他教程。

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. 桌面上的“tut.erl”。 Content might look like this: 内容可能如下所示:

-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 documentation More info on the shell, look here: Shell module 更多信息请参考此处的文档: Erlang官方文档有关shell的更多信息,请查看: Shell模块

Hope this gets your started. 希望这能让你开始。

You can also create an initialization file named .erlang under YourErlangInstallationPath\\usr\\ 您还可以在YourErlangInstallationPath\\usr\\下创建名为.erlang的初始化文件

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文件。

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. 当我在记事本中保存文件时,它添加了.txt,所以我保存在unicode中。 fixed 固定

If you are still getting "tut:erl:none: no such file or directory", the file name is wrong. 如果您仍然“tut:erl:none:没有这样的文件或目录”,则文件名错误。 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. 如果您打开Windows命令提示符并移动到桌面并键入“dir”,您将看到tut.erl实际上名为tut.erl.txt。 type "ren tut.erl.txt tut.erl" and now your compile will work. 输入“ren tut.erl.txt tut.erl”,现在你的编译工作正常。

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. 当werl的当前工作目录与要编译的文件相同时,文件名将作为参数给出,而不包含整个路径。 Otherwise, for eg. 否则,例如。 Assuming tut.erl is placed at C:\\ErLang tutorials, one may try compiling as, 假设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 使用转义序列给出反斜杠

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM