Can I add include directories to the erl command?
Asked Answered
M

2

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.

Mother answered 4/12, 2010 at 16:45 Comment(0)
M
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.

Mims answered 5/12, 2010 at 3:36 Comment(2)
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.Mother
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.Kaplan
C
2

you can set ERL_COMPILER_OPTIONS.

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

Cushing answered 5/12, 2010 at 21:42 Comment(1)
So would that work like this: ERL_COMPILER_OPTIONS='[{i,"/home/trotter/code/open-source/yaws/include"}]' erl ?Mother

© 2022 - 2024 — McMap. All rights reserved.