I am unable to use `ejabberd_auth` in my **helloworld** project - erlang

I am unable to use ejabberd_auth in my helloworld project.
-behaviour(ejabberd_auth).
...
....
try_register(<<"username">>, <<"example.com">>, <<"secret_password">>).
With that I get the error warning:
helloworld.erl:15: Warning: behaviour ejabberd_auth undefined
-import(ejabberd_auth, [try_register/3]).
...
....
try_register(<<"username">>, <<"example.com">>, <<"secret_password">>).
With this I get:
exception error: undefined function ejabberd_auth:try_register/3
Why am I unable to access ejabberd_auth?
I am using IntelliJ Idea, with the Erlang plugin installed.
Thank you all in advance.
UPDATE:
I'm on Ubuntu 16.04 LTS

I can get you past that error. Here's how...
When I compile a module in the erlang shell, the compiler creates a .beam file in the same directory, which allows me to call functions defined in the module. In your case, if you cd into the directory:
.../ejabberd/ebin
you will see all the ejabberd .beam files, including ejabberd_auth.beam. If you start an erlang shell in that directory, then issue your function call (don't compile anything), you won't get that error anymore.
But, then I get the error:
exception error: undefined function jid:nodeprep/1
in function ejabberd_auth:validate_credentials/3 (src/ejabberd_auth.erl, line 796)
in call from ejabberd_auth:try_register/3 (src/ejabberd_auth.erl, line`
There is no jid.beam file in that directory. But:
~/Downloads/ejabberd$ find . -name jid.beam
./deps/xmpp/ebin/jid.beam
You are going to have to figure out how to compile your module so that all the ejabberd modules are available to your program. See: ejabberd how to compile new module.
I am unable to use ejabberd_auth in my helloworld project.
Are you following a tutorial somewhere?

Related

make on ChicagoBoss failing with escript: exception error: undefined function rebar:main/1

I am trying to install ChicagoBoss based on the instructions here. Now, Make is failing with exception -
=ERROR REPORT==== 14-Dec-2022::11:15:33.605319 ===
beam/beam_load.c(148): Error loading module rebar:
please re-compile this module with an Erlang/OTP 25 compiler
escript: exception error: undefined function rebar:main/1
in function escript:run/2 (escript.erl, line 750)
in call from escript:start/1 (escript.erl, line 277)
in call from init:start_em/1
in call from init:do_boot/3
make: *** [compile] Error 127
I have further installed rebar3 using command -
homebrew install rebar3
I am running Erlang OTP/25 in mac. I haven't been able to understand if it's a problem with
rebar3
or
ChicagoBoss
The problem is with ChicagoBoss. It includes a rebar binary that was compiled with Erlang/OTP release 17, but Erlang/OTP release 25 can only use modules compiled with release 21 or later.
The rebar binary starts with the line #!/usr/bin/env escript, meaning that it looks for escript in the PATH. This picks up release 25, causing this problem. You could try installing release 24 or earlier to work around this.
You might find ASDF useful for switching between Erlang versions: https://github.com/asdf-vm/asdf-erlang

fatal error: zbar.h: No such file or directory

I downloaded the zbar library and cloned the opencv-zbar repo in my home directory. Then I ran the following command $cmake . which gave my the error
-- Could NOT find ZBAR (missing: ZBAR_LIBRARIES ZBAR_INCLUDE_DIR)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
ZBAR_LIBRARIES
linked by target "zbar_opencv" in directory /home/surabhi/opencv-zbar
-- Configuring incomplete, errors occurred!
See also "/home/surabhi/opencv-zbar/CMakeFiles/CMakeOutput.log".
I then made two changes in my CMakeCache.txt as follows
//Path to a file.
ZBAR_INCLUDE_DIR:PATH=/usr/include/zbar
//Path to a library.
ZBAR_LIBRARIES:FILEPATH=/usr/lib/libzbar.so
because the were set to NOTFOUND.
It then gave me no errors
-- Found ZBAR: /usr/lib/libzbar.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/surabhi/opencv-zbar
But when I run make
It gives the error:
fatal error: zbar.h: No such file or directory
#include <zbar.h>
^
compilation terminated.
I don't understand why I get this error as It says Found ZBAR when I run cmake.
Thanks in advance
You need to do actually use the include dirs somewhere in your CMakeLists.txt so CMake knows that you actually want to use these include paths.
Examples:
include_directories(${ZBAR_INCLUDE_DIR})
Or the more modern, recommended way:
target_include_directories(zbar_opencv PRIVATE ${ZBAR_INCLUDE_DIR})

Recompiling src file from cowboy prompt gives undefined function compile

I have my server running with
make run
Then I edited a file. Back in the cowboy terminal I type
(tunnel#127.0.0.1)2> c(clock).
Recompiling /root/tunnel/src/clock.erl
** exception error: undefined function compile:file/2
in function c:compile_and_load/2 (c.erl, line 259)
in call from c:safe_recompile/3 (c.erl, line 235)
(tunnel#127.0.0.1)3> compile(clock).
it seems that the shell recognizes the compile shortcut but it lists it as undefined.
How do I recompile while the server is running?
I also tried erlc src/clock.erl, which gave me a warning using export all but didn't respond with any error.

undefined symbol: luaopen_LuaXml

I had installed luaxml module using luarocks. I had used the luaxml to call in a lua script. But getting an error
Lua script:
xml = require("LuaXml");
local xobj = xml.eval('<Cmd Message="Hello"/>');
session:consoleLog("INFO","The message in the XML is "..xobj["Message"].."\n");
Error:
mod_lua.cpp:203 error loading module 'LuaXml' from file '/usr/local/lib/lua
/5.2/LuaXML_lib.so': /usr/local/lib/lua/5.2/LuaXML_lib.so: undefined symbol:
luaopen_LuaXml
stack traceback:
[C]: ?
[C]: in function 'require'
I had seen the concept of add libraries to Lua dynamically but i couldn't understand. Can anyone help me out. Briefly so that how to link the core module luaxml with the script.
Another question how can i test whether the installed module luaxml through luarocks is installed or not.
The output of nm -g /usr/lib/lua/5.1/LuaXML_lib.so tells us that this file exports luaopen_LuaXML_lib, not luaopen_LuaXML, which is what require("LuaXml") needs.
Now I don't know why require("LuaXml") is opening /usr/lib/lua/5.1/LuaXML_lib.so. It should be looking for LuaXM.so or LuaXml.lua, in this order.
LuaXML works by loading LuaXml.lua, which does require("LuaXML_lib"). This then will load LuaXML_lib.so.
Perhaps there is a mistake in your LUA_CPATH or package.cpath.

What does "redefining module" error in erlang mean?

I added the mochijson2.erl module to my ejabberd src directory but when I try to compile the code I get the following error:
./mochijson2.erl:8: redefining module
Where could this module be defined? I don't have it in my source.
It means your module has two -module(...) directives, which is not allowed. Check the source code of the module.

Resources