Niall
Niall

Reputation: 167

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)

Upvotes: 11

Views: 18199

Answers (6)

Chawathe Vipul S
Chawathe Vipul S

Reputation: 1696

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,

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

Note:

  1. Without double quotes the : causes syntax error
  2. The backslash is given using escape sequence

Upvotes: 0

Len
Len

Reputation: 1

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.

Upvotes: 0

Rrainsmith
Rrainsmith

Reputation: 11

I recently tried Erlang on windows.

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!

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

Upvotes: 1

Warren Young
Warren Young

Reputation: 42323

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.

Upvotes: 17

detay
detay

Reputation: 1072

You can also create an initialization file named .erlang under 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.)

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

Upvotes: 1

Mazen Harake
Mazen Harake

Reputation: 1726

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.

Upvotes: 10

Related Questions