I have compiled my Erlang module using
rebar compile
using the following option in rebar.config
{erl_opts, [native, {hipe, [verbose]}, warnings_as_errors, debug_info]}.
{eunit_compile_opts, [native, {hipe, [verbose]}, warnings_as_errors, debug_info]}.
I see that the code is indeed compiled to native since I see Hipe messages during compilation and the .beam file size are also larger than non-native compilation.
However when I run
rebar eunit
which tests my module I always get false for
code:is_module_native(?MODULE)
within my module under test.
Why does rebar not run my eunit test as native code?
I have additionally added this line to the reltool.config file,
{app, hipe, [{incl_cond, include}]},
rebar 2.1.0-pre 17 20140421_192321 git 2.1.0-pre-166-ged88055
Your code is recompiled when you run "rebar eunit" using the compile options defined by
{erl_opts, [native, {hipe, [verbose]}, warnings_as_errors, debug_info]}.
and modified by the compile options defined by
{eunit_compile_opts, [???]}.
Did you check these options?
Related
First of all, 'rebar doc' works sometimes and sometimes not. It is strange.
Rebar version which I'm using is 2.5.1
My folder structure is:
Header_Directory
1.1 apps
1.1.1 sub_dir_1
1.1.2 sub_dir_2 / include
1.1.3 sub_dir_3
1.2 deps
1.3 confs
rebar.config
Modules in sub_dir_3 also use some include files from sub_dir_2/include folder.
The error I get when I use the command rebar doc is:
.sub_dir_3/src/my_log_worker.erl, in module header: at line 9: file
not found: some.hrl edoc: skipping source file
'sub_dir_3/src/my_log_worker.erl': {'EXIT',error}. edoc: error in
doclet 'edoc_doclet': {'EXIT',error}. ERROR: doc failed while
processing /home/learn/header_directory/apps/sub_dir_3: {'EXIT',error}
I do 'rebar clean' and then 'rebar compile' prior to 'rebar doc'
Also,when I do it in erl shell, I get error.
edoc:file("some_log_worker.erl", []).
edoc: error reading file 'some_log_worker.erl'.
** exception exit: {error,enoent}
in function edoc:read_source/2 (edoc.erl, line 664)
in call from edoc_extract:source/3 (edoc_extract.erl, line 52)
in call from edoc:read/2 (edoc.erl, line 537)
in call from edoc:file/2 (edoc.erl, line 116)
Is there any way by which I can include my hrl file either in rebar.config or edoc options?
I have '{edoc_opts, [{ i, "apps/sub_dir_3/include" }]}.' in rebar.config, still of no help.
It looks like you didn't follow the rebar/OTP conventions:
OTP Conventions
Rebar expects projects to follow the OTP conventions as described in
the OTP Design Principles document: Applications
An application should consists of the following set of directories:
src
ebin
priv
include
and have an application resource file: ebin/example_project.app or
src/example_project.app.src. In the later case, the
ebin/example_project.app file is generated from the
src/example_project.app.src one automatically during the compilation
phase.
Rebar & OTP convetions
I recommend you to move to that file organisation, it will be really much simpler to benefit from standard tools like rebar.
Yes, it is always in the best interest to follow the OTP principles. However, it worked for my app structure.
The only problem was because of #headerfile annotation in the erlang modules. Somehow, I don't know how to correctly use the #headerfile annotation.
Thanks for all the help. :)
I'm trying to add lager to a simple erlang.mk project. I understand lager uses parse transforms, so you have to set compile flags accordingly; so following advice from here:
Lager calls failing during Common Test test runs
my Makefile looks as follows:
PROJECT = hello_erlang_mk
DEPS = cowboy lager
# this must be first
include erlang.mk
# Compile flags
ERLC_COMPILE_OPTS= +'{parse_transform, lager_transform}'
# Append these settings
ERLC_OPTS += $(ERLC_COMPILE_OPTS)
TEST_ERLC_OPTS += $(ERLC_COMPILE_OPTS)
The release builds fine but somehow lager never seems to be included:
Eshell V5.10.4 (abort with ^G)
(hello_erlang_mk#127.0.0.1)1> lager:info("~s is ~s!", [lager, cool]).
** exception error: undefined function lager:info/2
Anyone have any pointers on how to get lager working within an erlang.mk project ?
[I'm using Erlang R16B03, Ubuntu 14.04]
Thanks.
I believe there is nothing to do with erlang.mk. The problem is -- you try to call lager:info from the shell. But actually there is no such function in the lager module. lager:info is just a command for parse transform that is unfolded to some other (more complex) constructions during compilation time.
If you want to check if you application contains lager, you can try from shell lager:status() for example (which is 'honest' function in the lager module). Or lager:module_info().
Forgive me. Noob error. application:start(lager). Sorry.
I downloaded the source of LuaJIT and compiled it with msvc120.dll (VS 2013 x64). When I run it from the command line I have no problems executing some basic lua. Now the LuaJIT installation guide mentions moving luajit.exe and lua51.dll into their own folder. From there it says to create a lua folder and under that a jit folder with the contents of src/jit moved underneath the newly created jit folder.
From my understanding my folder should look like and contain:
luajit.exe
lua51.dll
/lua
/jit
bc.lua
[rest of jit files]
vmdef.lua
Is this correct or am I missing files?
Now after I built my luajit I tried to wire it up into my luarocks to act as my interpreter using
install.bat /LUA C:\LuaJIT\2.0.3\[folder with above content]
However this cannot find the header files. I then copied over what are the header files into the folder above and that wires it up, but I can never actually get anything to compile when pointed over to LuaJIT. Edit: The error I get is the following,
C:\LuaJIT\2.0.3\bin\lua51.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2D0
Error: Failed installing dependency: https://rocks.moonscript.org/luafilesystem-1.6.2-2.src.rock - Build error: Failed compiling module lfs.dll
Is the correct way to handle this to simply point to my lua binaries and from there leverage LuaJIT to run my files or am I doing something wrong with wiring up LuaJIT and luarocks? The former seems to work for the most part, since I only ran into one library compilation issue, lua-cjson.
I've run on exactly the same problem, but they've found a solution right here:
https://github.com/keplerproject/luafilesystem/issues/22
I knew that for "linking DLLs statically" there is a so-called "export" .lib file, which is passed to the linker (and not the DLL itself).
So, for example, when compiling, LuaRocks was doing this:
cl /nologo /MD /O2 -c -Fosrc/mime.obj -ID:/LuaJIT-2.0.4/include/ src/mime.c -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DNDEBUG -DLUASOCKET_API=__declspec(dllexport) -DMIME_API=__declspec(dllexport) mime.c
link -dll -def:core.def -out:mime/core.dll D:/LuaJIT-2.0.4/bin/lua51.dll src/mime.obj
My LuaJIT was compiled from source in D:\LuaJIT-2.0.4\src, but I made two folders myself: D:\LuaJIT-2.0.4\include with all *.h files copied from src and D:\LuaJIT-2.0.4\bin with luajit.exe, lua51.dll, and then later lua51.exp and lua51.lib. Still same error, but this was the right track.
Fix
Now, check where your LuaRocks configs are:
luarocks.bat help
Scroll down to a section like:
CONFIGURATION
Lua version: 5.1
Configuration files:
System: D:/luarocks/config-5.1.lua (ok)
User : (... snip ...)
Edit the System configuration file, specifically see the part:
variables = {
MSVCRT = 'VCRUNTIME140',
LUALIB = 'lua51.dll'
}
Here! LUALIB should be the .lib file. If your export lib is alongside the DLL, you just need to change to:
variables = {
MSVCRT = 'VCRUNTIME140',
LUALIB = 'lua51.lib' -- here!
}
Verification
And now:
luarocks.bat install luasocket
(...)
link -dll -def:core.def -out:socket/core.dll D:/LuaJIT-2.0.4/bin/lua51.lib src/luasocket.obj (...)
(...)
luasocket 3.0rc1-2 is now built and installed in D:\luarocks\systree (license: MIT)
Note the first argument passed to the linker.
I looked through the questions here on StackOverflow and Googled around for an example of setting up a Basic NIF project in rebar for wrapping a C++ library.
I used to library project on GitHub as a guide:
https://github.com/tuncer/re2
My project is here:
https://github.com/project-z/emutton/
When I do a rebar compile && rebar eunit, I get a failure in the eunit test because it cannot find emtn.so:
$ rebar compile && rebar eunit
==> emutton (compile)
==> emutton (eunit)
undefined
*** test module not found ***
**emtn
=ERROR REPORT==== 25-Jun-2013::12:21:55 ===
The on_load function for module emtn returned {error,
{load_failed,
"Failed to load NIF library: 'dlopen(/.../source/emutton/priv/emtn.so, 2): image not found'"}}
=======================================================
Failed: 0. Skipped: 0. Passed: 0.
One or more tests were cancelled.
ERROR: One or more eunit tests failed.
ERROR: eunit failed while processing /.../source/emutton: rebar_abort
When I call rebar compile, it is only producing a single driver file, emtn_drv.so and no emtn.so:
$ tree priv
priv
└── emtn_drv.so
0 directories, 1 file
I have an echo statement in c_src/build_deps.sh that I don't see output when I call rebar clean. It seems to behave as though my pre_hook and post_hook in rebar.config are completely ignored:
{pre_hooks, [{compile, "c_src/build_deps.sh"}]}.
{post_hooks, [{clean, "c_src/build_deps.sh clean"}]}.
Examples of no output shown from rebar:
$ rebar compile
==> emutton (compile)
$ rebar clean
==> emutton (clean)
Because I have cloned tuncer's RE2 bindings project and when I do a rebar compile see output from his build_deps.sh script. The permissions on mine match those on his:
-rwxr-xr-x 1 ajl staff 891B Jun 25 12:30 c_src/build_deps.sh
Any idea what I'm missing here? I believe that rebar is configured correctly to call out to the script and do the compilation.
Your problem is that the line in your rebar.config
https://github.com/project-z/emutton/blob/master/rebar.config%20#L1
Doesn't match what you attempt to load
https://github.com/project-z/emutton/blob/master/src/emtn.erl#L25
You should either change the rebar.config to
{port_specs, [{"priv/emtn.so",["c_src/emtn_nif.c"]}]}.
and change emtn.erl to
erlang:load_nif(filename:join(PrivDir, "emtn"), 0). % ?MODULE is an atom, I believe you need a string
Or change emtn.erl to
erlang:load_nif(filename:join(PrivDir, "emtn_drv"), 0).
I user rebar to make a eunit test with command "rebar compile eunit",but get a error info:
==> myapp (compile)
==> myapp (eunit)
src/myapp_app.erl:8: badly formed 'include_lib'
src/myapp_app.erl:26: undefined macro 'assertNot/1'
ERROR: eunit failed while processing /Users/Dao/ErlProject/myapp: rebar_abort
I really don't know how this mean,who can tell me why?
PS:my english is poor,please forgive me
myapp_app.erl like this:
-ifdef(TEST).
-include_lib(“eunit/include/eunit.hrl”).
-endif.
........
-ifdef(TEST).
simple_test() ->
ok = application:start(myapp),
?assertNot(undefined == whereis(myapp_sup)).
-endif.
and It's came from here:https://github.com/rebar/rebar/wiki/Getting-started
I follow the step,but got the error!
My erlang version is R15B03
os: OS X Lion
Based on the code you've presented, I believe the problem has to do with the doublequotes you're using. Right now, you are using some kind of slanted quotes, which, if I copy and paste it and use that same definition myself in a test module, it generates the same error.
You want to make sure for your doublequotes that you use "normal" ones:
" (ASCII 34) instead of ”, which is unicode.
So change
-include_lib(“eunit/include/eunit.hrl”).
to
-include_lib("eunit/include/eunit.hrl").
Make sure you include eunit in the following way:
-include_lib("eunit/include/eunit.hrl").
Needless to say, make sure you installed eunit at all. So far I remember, it may be not installed by default in some Ubuntu versions, for instance.