Sunday, January 24, 2010

Qt Mobility Messaging API on Linux

Getting Qt Mobility Messaging API to work on Linux (my Ubuntu Karmic Koala 9.10 system) needs some tricks.

The easiest way of test your setup is by compiling the Qt Mobility example writemessage.

Using my initial installation of Qt Mobility I got this error:
Starting: /usr/bin/make -w
.......
/usr/bin/ld: cannot find -lQtMessaging_tp
collect2: ld returned 1 exit status
make: *** [message-merge] Error 1
Exited with code 2.
Error while building project message-merge
When executing build step 'Make'

The most important error message is "cannot find -lQtMessaging_tp" which means that Qt Mobility Messaging library has not been properly built.



















Qt Mobility on Linux requires QMF.


The Qt Mobility Messaging API documentation points this out:


On Linux QMF is required to be installed and the QMF_INCLUDEDIR and QMF_LIBDIR environment variables set to the messagingframework/src/libraries/qtopiamail and build/messagingframework/image/lib directories respectively.

To install QMF, checkout the latest QMF from Gitorious:
git clone git://gitorious.org/qt-labs/messagingframework.git qt-messagingframework
If you don't have git or don't want to use it, you can also download QMF as tarball archive.
Then build it:
export PATH=/opt/qtsdk-2010.01/qt/bin:$PATH
qmake "QMF_INSTALL_ROOT=$PWD/image" qmf.pro
make
make install
Now you need to rebuild Qt Mobility with Messaging (QMF) support (change paths as necessary):

export PATH=/opt/qtsdk-2010.01/qt/bin:$PATH
export QMF_INCLUDEDIR=/opt/qt-messagingframework/src/libraries/qtopiamail
export QMF_LIBDIR=/opt/qt-messagingframework/image/lib
./configure
make
make install
Make sure it says "Checking QMF ... OK" during configure.
Add the following to your $HOME/.profile script:
necessary):
# Qt Mobility
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/qt-mobility-src-1.0.0-tp2/install/lib:/opt/qt-messagingframework/image/lib
export QMF_INCLUDEDIR=/opt/qt-messagingframework/src/libraries/qtopiamail
export QMF_LIBDIR=/opt/qt-messagingframework/image/lib
Once Qt Mobility Messaging + QMF is set, to use it add the following to your .pro project file:
CONFIG += mobility
MOBILITY = messaging
The writemessage example additionally uses the following workaround to link QMF library:
symbian|win32 {
} else {
# Temporarily link against local qtopiamail lib (should be part of the platform)
LIBS += -L $$(QMF_LIBDIR) -lqtopiamail
}
Then you should be set.

Troubleshooting

If you get this error while building a Qt Mobility Messaging app:
/usr/bin/ld: warning: libqtopiamail.so.1, needed by /opt/qt-mobility-src-1.0.0-tp2/install/lib/libQtMessaging_tp.so, not found (try using -rpath or -rpath-link)
/opt/qt-mobility-src-1.0.0-tp2/install/lib/libQtMessaging_tp.so: undefined reference to `QMailAccountKey::operator|=(QMailAccountKey const&)'
It means you have built Qt Mobility Messaging module properly, but you haven't specified the library path to QMF. See above workaround to link QMF library.
If you get this error when running a Qt Mobility Messaging app:
error while loading shared libraries: libqtopiamail.so.1: cannot open shared object file: No such file or directory
exited with code 127
It means you haven't set QMF_LIBDIR properly. If you have, you may need to restart your computer.

No comments:

Post a Comment

Be the first to comment!