Erlang Study

Posted in   Erlang   at 2011-03-03

Erlang程序编译运行的方法

方法1:直接在shell中编译运行

1
2
3
4
5
6
hello.erl
    -module(hello).
    -export([start/0]).

    start() ->
        io:format("Hello world~n").
$ erl
>c(hello).
{ok,hello}
>hello:start().
Hello world
ok
>

方法2:在命令行编译运行

$ erlc hello
$ erl -noshell -pa path -s hello start -s init stop

方法3:把方法2的命令写入一个脚本,作为批处理的东西

hello.sh
    #!/bin/sh
    
    erl -noshell -pa path -s hello start -s init stop
$ ./hello.sh

方法4:用makefile来编译,

一个标准的makefile模板

.SUFFIXES: .erl .bem .yrl .erl .beam

erlc -W $<

.yrl .erl

erlc -W $<

ERL=erl -boot start_clean MODS=mod1 mod2 mod3 …

all:compile compile: ${MODS:%=%.beam} subdirs special1.beam: special1.erl

${ERL} -Dflag | -w0 special1.erl

application1: compile

${ERL} -pa Dir1 -s application1 start Arg1 Arg2

subdirs:

cd dir1; moke
cd dir2: make

clean:

rm -rf *.beam erl_crash.dump
cd dir1; make clean
cd dir2; make clean
comments powered by Disqus