ZeroMQ supports different languages and thus allow an easy interprocess data exchange between different programs.
For example a C program can easily exchange data with a Python or Java program.
Install ZeroMQ
To install ZeroMQ, is necessary to compile the source code and generate the library.To do so, under ubuntu :
- sudo apt-get install build-essential
- sudo apt-get install libtool
- sudo apt-get install automake
- sudo apt-get install autoconf
- sudo apt-get install uuid-dev
- Download the tarball for the libsodium from the Libsodium website
- Extract the tarball in a directory
- go in the directory
- ./configure
- make
- sudo make install
- Download the tarball from the ZeroMQ website
- extract the tarball in a directory
- go in the directory
- ./configure
- make
- sudo make install
On some systems is better to run :
sudo ldconfig to update the system library cache, otherwise it is requested a reboot of the machine.
Install Czmq
In order to bind the library with the C language is necessary to compile the library Czmq- git clone https://github.com/zeromq/czmq
- cd czmq
- ./autogen.sh
- ./configure
- make
- sudo make install
- sudo ldconfig
Use ZeroMQ in your code
Usually the libraries by default are placed in /usr/local/lib.
In order to use ZeroMQ in a project is enough to add to the linker phase the two main libraries, zeroMQ and the binding one.
Usually the name is the name of the library minus the "lib" part and the extension.
So for example, if the zeroMQ main library is called libzmq.so.3, the library name to be used in the linker will be zmq.
For example in a makefile :
LIB0MQ = -l zmq -l czmq # define variable LIB0MQ containing the libraries directive
................
................
CC = gcc $(CFLAGS) -c
CC1 = gcc $(CFLAGS)
LD = $(LIB0MQ)
AS = as $(AFLAGS)
Then in the main preparation of the code :
projectName: $(projectName_objs)
$(CC1) -o $(APPNAME) $(projectName_objs) $(LD)
Cross compile for ARM
To cross compile for ARM, be sure to have installed a ARM toolchain other the packages described above, and when ready to compile ZeroMQ, starts with :- ./configure --host=arm-none-linux-gnueabi
- make
Compile the examples
To compile the examples is possible to use the build script provided with the examples.
However it can be overshooting.
I suggest to use this approach :
- copy the examples in a local directory
- run : gcc -Wall -g name_example.c -lzmq -o name_example
No comments:
Post a Comment