Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Erlang code on Windows

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

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?

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:

  (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)
like image 775
Niall Avatar asked Aug 14 '09 16:08

Niall


2 Answers

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

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.erl file is.

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. If tut.erl is on the Desktop, the command will be something like this on Vista or Windows 7:

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

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

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

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.

like image 183
Warren Young Avatar answered Oct 03 '22 02:10

Warren Young


After you install Erlang open the shell and do:

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:

-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

Hope this gets your started.

like image 30
Mazen Harake Avatar answered Oct 03 '22 01:10

Mazen Harake