Question

I'm trying to generate an Erlang Cowboy release by scrupulously following (e.g. cut-and-paste) the Getting Started instructions at:

https://github.com/extend/cowboy/blob/master/guide/getting_started.md

All goes well until I create Makefile and execute$ make. The compile process terminates as follows:

...
make[1]: Leaving directory `/home/lloyd/hello_erlang/deps/cowboy'
ERLC   hello_erlang_app.erl hello_handler.erl hello_erlang_sup.erl
compile: warnings being treated as errors
src/hello_handler.erl:3: behaviour cowboy_http_handler undefined
make: *** [ebin/hello_erlang.app] Error 1

I've triple checked my code but can't see anything I've missed.

So, is this my error? Or a bug in the Getting Started instructions or in Cowboy itself? If it's my mistake, how can I fix?

I've posed this question to essen@ninenines.eu, but so far no response.

Was it helpful?

Solution

The cause of the problem is twofold:

  1. In your module you have a behaviour declaration -behaviour(cowboy_http_handler).. This is perfectly correct.
  2. When you compile the file the compiler can't find the cowboy_http_handler module in its search path

This causes the error as the behaviour declaration tells the compiler to go out and find that module and find out which callback functions the behaviour expects. Normally if the compiler can't find the behaviour module, or if it can find and there are some callbacks missing then it issues a warning about this and just continues. However your Makefile sets a compiler option which treats all warnings as errors so the compilation fails.

There are (at least) three solutions to this:

  1. Remove the compiler option and accept you get a warning.
  2. Make sure the compiler can find the behaviour module and do the checking. A simple way of doing is to add a -pa Dir option for the cowboy beam file directory so it can find the file.
  3. Set up Erlang so that it automatically finds the cowboy directory, for example with $ERL_LIBS.

Note that even if the compiler finds the right module you still have to make sure that when you run the system Erlang can find the directory. There is no automatic equivalence between the compile-time and run-time environments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top