7

When compiling an erlang file with erlc I can add additional include directories like so:

erlc -I /home/trotter/code/open-source/yaws/include src/myapp.erl

When I'm compiling from within erl though, I don't see a way to do this on the command line. Instead, I have to do the following within the repl:

> compile:file("src/myapp", 
               [verbose,
                report_errors,
                {i,"/home/trotter/code/open-source/yaws/include"}]).

Is there a better way to do this that I don't know about, such as passing some command line argument to erl? If not, any suggestions for drying this up that don't require me to type nasty paths everytime I compile.

Trotter
  • 1,270
  • 11
  • 13

2 Answers2

6

I rarely compile from the shell - only for small test scripts with c(foo). My setup is this:

I have a build infrastructure. make builds the software (make is just a wrapper for rebar here). I can then build code from within emacs by hitting F12 bound to the compile emacs command. In vim you can do the same with the :make command if my vim memory serves me (it has been a couple of years). Now this of course builds the code and throw it into an ebin dir.

The next step is to start Erlang with knowledge about the ebin dir:

 erl -pa ./ebin

which means that any reference to module foo goes and checks for ./ebin/foo.beam. When I then figure out I have to fix some code, I fix it in the editor, compile the code with F12 and then execute l(foo) in the shell which hot-loads the code.

It also has the advantage that any compilation error is now under the jurisdiction of the editor so I can quickly jump to the error and fix it.

I GIVE CRAP ANSWERS
  • 18,739
  • 3
  • 42
  • 47
  • Ok, that's totally a better solution to my problem. I did not know that I could use l(foo) to hot-load compiled code. – Trotter Dec 06 '10 at 13:15
  • To make things easier, I created a .erlang file in the project root with `code:add_patha("./dict").`. It added the "dict" path to the beginning of the path search list every time I run `erl` on that project. – Carlosedp Dec 01 '14 at 13:12
2

you can set ERL_COMPILER_OPTIONS.

see http://www.erlang.org/doc/man/compile.html

sg2342
  • 61
  • 2
  • 1
    So would that work like this: ERL_COMPILER_OPTIONS='[{i,"/home/trotter/code/open-source/yaws/include"}]' erl ? – Trotter Dec 06 '10 at 13:13