Compiled and installed ejabberd version 15.10 on ubuntu 14.04 machine in /opt/ejabberd directory.
In the older version the module can be compiled directly with erlc command and then pasted to ejabberd module dir(or symbolic linked) which was very efficent way to develop the modules.
But after upgrading to newer ejabberd version when using the INFO_MSG()/2 from logger.hrl the ejabberd fails to load the module.
When compiled by placing the module file inside the ejabberd src directory and running make in ejabberd directory as suggested at https://www.ejabberd.im/ejabberd-13.10 and ejabberd how to compile new module the module works.
But this is very inefficient compared to the older method of compiling and running the modules with elrc command directly.
Is the latter approach the right method, if so why was it changed and where are the official docs that explain compiling with latter approach.
you can compile ejabberd module like this
erlc -I /lib/ejabberd/include -o /lib/ejabberd/ebin /home/sunil/Documents/ejabberd_custom_modules/mod_profile.erl
In this example /lib/ejabberd/include is header file (.hrl) path , /lib/ejabberd/ebin* is binary file path of ejabberd and '/home/sunil/Documents/ejabberd_custom_modules/mod_profile.erl is source file path.
Right way to compile your custom ejabberd module (suggested by process-one) is :-
put your module into ejabberd/src folder.
come to ejabberd directory in terminal and run command $ sudo make
it will show you that your module is compiled. You can check ebin directory for .beam file that is result of your compilation.
Now to run your module
$ sudo make install
Add your module into config file at /etc/ejabberd/ejabberd.yml
restart your ejabberd and your custom module will be running.
Another way of compiling with erlang shell is :-
start your erlang to load all included files required by ejabberd module from ebin directory.
> erl -pa <your path to ejabberd/ebin>
You can also give multiple paths separated by space if you are including files from multiple places. Like
> erl -pa <path1/ebin> <path2/ebin>
This will start erlang shell. Next things you need to do are :-
do
> cd("<path to your module.erl file>").
compile your module
> c(your module).
Your module.beam file will be generated as a result of your compilation.
Related
I have downloaded ejabberd and even done a :
sudo port install ejabberd
After this, I am trying to install the ejabberd-websocket module from here : https://github.com/superfeedr/ejabberd-websockets
However, try as I might I am not able to install it by issuing :
./build.sh
This is the error that I am getting :
Recompile: src/mod_websocket
src/mod_websocket.erl:22: can't find include file "ejabberd.hrl"
src/mod_websocket.erl:23: can't find include file "jlib.hrl"
src/mod_websocket.erl:36: undefined macro 'DEBUG/2'
src/mod_websocket.erl:16: function process/2 undefined
src/mod_websocket.erl:14: Warning: behaviour gen_mod undefined
src/mod_websocket.erl:95: Warning: function validate_origin/1 is unused
src/mod_websocket.erl:171: Warning: function build_stream_end/0 is unused
I even have erlang as I installed it via macports. However, I am not able to install the module.
I am using Mac OSX Mountain Lion.
Any help would be great.
I can help you get around some of your issues. At least in my case, ejabber installed into a different location than this project expects. If you open Emakefile you will see it tries to include /usr/lib/ejabber/include, but in my case I had to remove the /usr part so it is just /lib/ejabberd/include. It may not be exactly the same in your case, but you just need to find your ejabber installation and make sure those directory paths match.
My Emakefile for reference
{'src/mod_websocket', [{outdir, "ebin"},{i,"/lib/ejabberd/include"},{i,"/lib/ejabberd/include/web","src"}]}.
{'src/ejabberd_xmpp_websocket', [{outdir, "ebin"},{i,"/lib/ejabberd/include"},{i,"/lib/ejabberd/include/web","src"}]}.
{'src/ejabberd_websocket', [{outdir, "ebin"},{i,"/lib/ejabberd/include"},{i,"/lib/ejabberd/include/web","src"}]}.
I also had to modify the build.sh script, but I don't think it solved any of my problems
#!/bin/sh
erl -pa /lib/ejabberd /lib/ejabberd/include /lib/ejabberd/ebin -pz ebin -make
Erlang RabbitMQ Client not working...(http://www.rabbitmq.com/erlang-client-user-guide.html)
Somehow my RabbitMQ Erlang client is not working.. It gives "can't find amqp_client.hrl" error when i try to compile it using
ERL_LIBS=deps erlc -o ebin amqp_example.erl
Here are the steps I have taken.
Created module amqp_example.erl
Created deps folder
Put rabbit-common and amqp_client inside deps folder
Compiled using ERL_LIBS=deps erlc -o ebin amqp_example.erl
Can anyone let me know what I am missing. BTW I am very new to erlang.
Also, i want to create a application which can connect using websocket to ERlang (Preferably Cowboy) and from there I can connect to rabbitMQ
Can anyone let me know what I am missing.
The compiler error indicates that erlc is unable to locate the amqp_client.hrl header file. Post some example code detailing how you're including the header file. Normally you would use include_lib("amqp_client.hrl"). if you're telling the compiler about the location of the amqp_client application by setting the ERL_LIBS environment variable.
Got it worked. It required rabbitmq server which was not compiled properly.
I wanted to integrate Elixir into our project, and the good old codes don't use rebar, so I think writing the rules for building .ex files into Emakefile may be a good idea, yet the man page here didn't mention anything relevant.
Edit:
Our team works mainly in Windows environment, but the deployment will be done on Linux servers, so I need a cross-platform solution. Since Erlang itself is cross-platform, I wanted to do it with erl -make command.
Of course I can write a Makefile, but then I'll need a build.bat or something alike to build the code in our developing environments, since we don't have make command on our dev' machines.
Anyone have a better idea?
Update:
In case anyone wants to know, I'm doing it this way:
Copy the lib/elixir directory in the Elixir source tree to our source dir, say some_project/src/tools/elixir.
Add some_project/src/tools/elixir/src/elixir_transform.erl and some_project/src/tools/elixir/src/* to the Emakefile, in that order. Set the output dir to some_project/ebin (All the other .beam files are located there).
Copy src/elixir.app.src in the Elixir source tree to some_project/ebin/elixir.app, and edit it to fix the version code.
Build the Erlang code by running erl -pa ebin -make, in some_project dir.
Build the Elixir compiler by running erl -pa ebin -s elixir_compiler core -s erlang halt
Now we have a working Elixir environment in our code, and I use the following escript to build our custom .ex files:
%%! -pa ./ebin
main(_) ->
ExList = [
<<"source_1.ex">>,
<<"source_2.ex">>,
<<"source_3.ex">>],
application:start(elixir),
gen_server:call(elixir_code_server, {compiler_options, [{docs, true}, {debug_info, true}]}),
[elixir_compiler:file_to_path(F, <<"./ebin">>) || F <- ExList],
erlang:halt(0).
If you want to explicitly compile Elixir, I would go with the Makefile approach since it will always be supported by Elixir. However, I would recommend the precompiled binaries or even assume Elixir is installed in each developer machine. You can even add a task to your Emakefile to guarantee everyone is using the proper Elixir version.
Finally, about compiling your own Elixir code, I would recommend simply using mix. mix is a binary that ships with Elixir and you can simply do ./src/tools/elixir/bin/mix compile from your Emakefile.
In case using mix is not possible, you should use the parallel compiler, since it will compile files using all cores available in your machine and it will automatically detect and solve dependency in between files. Here is an example of calling the parallel compiler from erlang:
https://github.com/basho/rebar/pull/347/files#L1R62
The API is very simple. It expects a list of file names to compile as binary and the directory to output files to as another binary.
In my project, i want to use mysql so i checkout this https://github.com/dizzyd/erlang-mysql-driver. I want to know how install the application so that my project can interact with it
Have a look at "rebar" - https://bitbucket.org/basho/rebar/wiki/Home
It can be used for installing dependencies, and for creating independent releases.
And a quick look at erlang-mysql-driver, that you want to use, shows that it is also using rebar for its dependency management.
rebar may complicate things if you have already started laying out your app (done some coding already) or if you are a newbie , however, if your project is an erlang/OTP app, then i suggest that you first organize you code according to the recommended file system like this:
MyProject--/src
/ebin
/lib
/include
/priv
/doc
/examples
/test
/Emakefile
The Emakefile is an important file. It maynot have a file extension. It enables the BIF: make:all() to compile all the erlang source modules you point it to and transfers all the .beam files to the destination you want.
For example: is i want all the modules in src to be compiled and transfer the beam files into ebin, i enter this into the Emakefile
{"src/*", [debug_info, netload,strict_record_tests,warn_obsolete_guard,{outdir, "ebin"}]}.
In that case i would start the erlang shell with its pwd() pointing in the folder MyProject, to enable the function call make:all() to find the file Emakfile so as to compile all my src files.
Now, suppose you have another OTP app which you want to have as an extra package in your build. If it OTP-like arranged as i have showed you, and not yet built i.e. not yet made, i mean with only its src and its folder ebin are empty or it ebin may be containing a .APP file already. Then you copy this OTP application into your lib folder, so that your application looks like this:
MyProject--/src
/ebin
/lib/some_otp_app-1.0
/include
/priv
/doc
/examples
/test
/Emakefile
then we would change our Emakefile to look like this:
{"src/*", [debug_info, netload,strict_record_tests,warn_obsolete_guard,{outdir, "ebin"}]}.
{"lib/some_otp_app-1.0/src/*", [debug_info, netload,strict_record_tests,warn_obsolete_guard,{outdir, "lib/some_otp_app-1.0/ebin"}]}.
In the folder MyProject, you can put a shell script that will start your project and add all relevant ebin paths to your nodes code path.the sh script may look like this:
#!/bin/bash
erl \
-name my_node#my_domain \
-pa ./ebin ./lib/*/ebin ./include \
-mnesia dump_log_write_threshold 10000 \
-eval "make:all()"
You can save this file as start_project.sh. Hence as you make changes to your source code, even at the time of starting your project, when you run the sh script with your terminal path pointing into the folder: MyProject, you do this:
$pwd
/export/home/your_user_name/MyProject
$sh start_project.sh
This would start your project at the node you entered in the script and would compile all src files which were changed when it was off. Not only this, you can as well call: make:all() in your shell whenever you make cahnges to your src code. then you would call: l(some_module) after making so that the erlang vm reloads the new object code of the compiled module.
So, your entire project will now appear like this:
MyProject--/src
/ebin
/lib/some_otp_app-1.0
/include
/priv
/doc
/examples
/test
/Emakefile
/start_project.sh
So if you substitute the erlang driver for mysql application with this "some_otp_app-1.0", everything will be fine. success!
Generally, when a Perl module installs an executable script, it somehow changes the #!/usr/bin/perl line to point to the appropriate Perl path. For example, if I used the perl installed at /usr/local/bin/perl to install the module, then the shebang line will be changed to #!/usr/local/bin/perl, so that the installed script will always use the version of perl that installed it.
What does this, and how can I do it in my own modules that install scripts?
Edit
Note that I am specifically talking about executable perl scripts that are distributed as part of a Perl module. Since a module is installed to a specific version of Perl, any scripts installed by that module must use that same version, so #!/usr/bin/env perl is wrong.
From http://metacpan.org/pod/ExtUtils::MakeMaker
EXE_FILES
Ref to array of executable files. The files will be copied to the INST_SCRIPT directory. Make realclean will delete them from there again.
If your executables start with something like #!perl or #!/usr/bin/perl MakeMaker will change this to the path of the perl 'Makefile.PL' was invoked with so the programs will be sure to run properly even if perl is not in /usr/bin/perl.