p0z3r

Wednesday, August 03, 2005

#ifdef KDE

Let me start this story with the lesson I learned. Discovering an oversight is a humbling event. Recently I had receieved requests to backport SuperKaramba to older versions of KDE. The problem is, KNewStuff was introduced in 3.3, so I had to get around that. I've dealt with conditionally removing code based on the version of KDE before, so I figured this would be a quick and easy task. Those are always famous last words as a deadline passes you by.

First things first, I used what was already defined to make sure that code only got included if you were using KDE > 3.3. That equates to #ifdef KDE_3_3 in our case. It worked great on versions of KDE < 3.3. However I received compile errors on 3.4.
undefined reference to `SKNewStuff::SKNewStuff[in-charge](ThemesDlg*)'

After consulting our buddies on irc.freenode.net #kde-devel, I had someone else going over my code. What we figured is that my SKNewStuff object wasn't getting created. This threw me for a bit because the same #ifdef is in other files and it works just fine.

Further examination by [mX] discovers that I was missing something. The header that defines the KDE_3_3 for the ifdef wasn't being included. *doh* So after a round of adding the proper includes, I finally had it compiling on both versions without fail.

After the svn commit, I received a mail from mattr offering a suggestion. There is a header file, kdeversion.h, that you can use instead of the defines I had. In my defense, the defines were there before I started working on the code. ;)

So, in the future, I'll use his suggestion. Here's an example of what you would do to implement it:
#include <kdeversions.h>

#if KDE_IS_VERSION(3,4,0)
//do stuff for KDE 3.4 or greater
#else
//do stuff for less than KDE 3.4
#endif

0 Comments:

Post a Comment

<< Home