Alexej Lotz, September 25th, 2008
Caution: The changes described below are integral part of ØMQ from version 0.4 onwards.
Introduction
This document and code-snippets contained inside are published under the MIT license. I also don’t take charge for completeness. The idea behind this document is to summarise required changes to get ØMQ framework to work under QNX Neutrino. I have used ØMQ version 0.3 and QNX Netrino 6.3.2. QNX is a software from “QNX Software Systems” (see www.qnx.com).
Building ØMQ core
First of all, QNX offers different development environments. You can choose between Linux/Windows - or Neutrino1 Host. Under Neutrino host you can use many GNU tools like autotools2. So the obvious idea is to run autogen.sh scrip directly under QNX. Well the problem here is that QNX (version 6.3.2) supports only the older version of autoconf (version 2.57), ØMQ seems to be based on 2.61.
The more common approach is to take an official ØMQ release and to use the configure script to crossbuild the framwork for QNX. ØMQ in the Version 0.3 did not support QNX natively. So if you try to run ./configure —host=i386-pc-nto-qnx following error occurs:
configure: error: Not supported os: i386-pc-nto-qnx
QNX Neutrino is a UNIX and implements POSIX API. So temporary solution is to cross-build the sources for a similar OS like Linux or FreeBSD. After doing some tests FreeBSD seemed to be suitable. The main reason for FreeBSD is the class
ysemaphore_t. Here you have the wrapper for a simple semaphore (once used to synchronise at most two threads). Under Linux you can use a mutex for that purpose. Under QNX Neutrino mutex behaves different to the Linux mutex. You can’t lock it twice from the same thread. So you can’t use it here.
Thus you have to take the #else part with a common semaphore3. To cross-build the sources for FreeBSD I have executed following script under Linux (under base directory of ØMQ sources):
./configure --host=i386-freebsd
Now you should have the right sources ready to be compiled for QNX. When trying to get the configure script ready for QNX I found following differences to the FreeBSD sources. Consequently to prior building process configure should generate a ZMQ_HAVE_QNX macro in platform.hpp header file. Further config.h file should be set correctly.
Here I found following differences:
- HAVE_LIBSOCKET_QNX - have natively the socket library, so this macro should be defined.
- HAVE_MEMORY_H - I did not find the memory.h header file under QNX, so this macro should be undefined.
- ZMQ_HAVE_QNX - Well, obviously this macro could be defined here also.
Compiling the sources
After you cross-built the sources for FreeBSD you are able to compile these sources for QNX. The easiest way to do so is to use the QNX Momentics IDE. The alternative is to write an own Makefile. Before you build the sources some source code modifications are necessary.
The first problem is the #include <poll.h> statement. For QNX this include should be #include <sys/poll.h>. I modified following files:
- poll thread.hpp
- ysocketpair.hpp
- bp_engine.cpp
- zmq_server.cpp
To be backward compatible following macro could be used instead:
#ifdef __QNX__
#include <sys/poll.h>
#else
#include <poll.h>
#endif
I did not test older version of QNX so I used following macro (suitable only for QNX Neutrino):
#ifdef __QNXNTO__
#include <sys/poll.h>
#else
#include <poll.h>
#endif
Next following compiler error occured in raw_message.hpp header file:
zmq/raw_message.hpp:81: error: ‘malloc’ undeclared (first use this function)
This can be solved with following include statement:
#ifdef __QNXNTO__
#include <malloc.h>
#endif
Now you can compile the sources. For QNX you should choose the right cross compiler. For i386 CPU it would be ntox86-g++-3.3.5.
To solve the linker error you should add the socket library from QNX into your compiling process.
With that information in mind you should be able to compile at least the ØMQ core sources and/or to build a ØMQ shared library.
Chatroom example
To test the library I used the chatroom example from the sources. There is one source code modification necessary to get this example to work correctly.
In the chatroom's display.cpp source file there is a following code at the end of the file:
cout << (char*) message.data ();
Here it seems, that the message string does not have a correct EOL statement at the end, so cout doesn’t print immediatelly. I modified this statement as follows:
cout << (char*) message.data () << flush;
I did not really figure out why this don’t worked without flush, but it seemed that the EOL character was not set right. I don’t know if it happens during input or during sending.
Building version 0.3.1
To build version 0.3.1 do exactly the same as above. Additionally you have to add following line to ip.cpp:
#include <stdlib.h>
Conclusion
ØMQ seems to be an interesting messaging framework. From my point of view it could show its full potential by supporting QNX. Here you can easily build embedded systems and try out different CPUs. Although QNX have a native message passing functionality, it only works inside QNX, so ØMQ have the ability to make QNX more interoperable. So as a user of both QNX and ØMQ I hope that QNX will find into main stream of ØMQ.