Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always got undef error of lager_transform when using lager log framework

Tags:

erlang

rebar

I want to use lager as my log utility and I have orgnazied my proj as below:

proj\
  |
  |--lager\
  |    |--src\
  |    |--ebin\
  |    |--...
  |     
  |--logserver\
  |    |--src\
  |    |--ebin\
  |    |--rebar.config
  |    |--...
  |
  |--rebar
  |

However, when I try to compile logserver, I always got the following error:

D:\proj\logserver>..\rebar compile

==> logserver (compile)
src/logserver_app.erl:none: error in parse transform 'lager_transform': {undef,
                                             [{lager_transform,
                                               parse_transform,
                                               [[{attribute,1,file,
                                                  {"src/logserver_app.erl",1}},  
                                                  ...

Can anyone know the reason? Thanks!

These is some additional information:

  • I am using Windows OS and using latest version of Erlang and rebar and lager.
  • lager itself has already been compiled. We can find the D:\proj\logserver>dir ..\lager\ebin\lager_transform.beam (This will succeed)
  • rebar's config file(D:\proj\logserver\rebar.config):

    ... {erl_opts, [{parse_transform, lager_transform}, debug_info,{d,'TEST'}, {i, "include"}, {src_dirs, ["src"]}]}.

    {lib_dirs, ["..\lager\ebin"]}. ...

like image 598
user1040933 Avatar asked Sep 08 '12 07:09

user1040933


2 Answers

If you already have lager in your deps then make sure that you move lager dependency first in rebar.config so that way it will compile first. Like so:

{deps,[
  lager,
  ..
]}.
like image 172
Jack Daniel's Avatar answered Sep 23 '22 02:09

Jack Daniel's


Did you add lager as a dependency in your rebar.config? I guess lager is not in the path.

From the rebar wiki:

To use lager in your application, you need to define it as a rebar dep or have some other way of including it in erlang’s path. You can then add the following option to the erlang compiler flags:

{parse_transform, lager_transform}

You can add 'lager' as a dependency by editing your rebar.config:

%% == Dependencies ==

%% Where to put any downloaded dependencies. Default is "deps"
{deps_dir, "deps"}.

%% What dependencies we have, dependencies can be of 3 forms, an application
%% name as an atom, eg. mochiweb, a name and a version (from the .app file), or
%% an application name, a version and the SCM details on how to fetch it (SCM
%% type, location and revision). Rebar currently supports git, hg, bzr and svn.
{deps, [application_name,
        {application_name, "1.0.*"},
        {application_name, "1.0.*",
         {git, "git://github.com/basho/rebar.git", {branch, "master"}}}]}.

In your case, that should be something like:

{deps, [{lager, ".*", {git, "git://github.com/basho/lager.git", "HEAD"}}]}.

More info about the rebar dependency manager here:

https://github.com/basho/rebar/wiki/Dependency-management

like image 31
Roberto Aloi Avatar answered Sep 24 '22 02:09

Roberto Aloi