Question

I am extremely new to Erlang, I am trying to compile my first Erlang module and am getting an error that the no such file exists, although it does in fact exist.

Any suggestions as to why I erl.exe is failing to compile useless.erl is greatly appreciated.

Many thanks in advance!

erl.exe command prompt (note modules does in fact contain useless.erl)

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

(useless.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).
Was it helpful?

Solution

With that form, you need to execute erl the same directory as the module you are trying to compile. You can specify a file path when you use the c function. This will create a .beam file in your current directory:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top