more comfortable approach for exporting dbus functions on windows

Ralf Habacker ralf.habacker at
Fri Mar 5 13:55:14 PST 2010

Tor Lillqvist schrieb:
>> Ok, I was about to point out that the __declspec(dllexport) syntax was msvc ony, and thus would break for mingw,
> As far as I know that syntax is fine in mingw, too?
>>  I'm not sure the KDE macros are correct for
>> all cases : for example I'm pretty sure that'll fail for static builds, as dllexport must not be used then.
> Yeah, that is the problem when going down the path of adding
> export/import decorations to header files: you need an ifdef mess to
> take care of all the possibilities:
this is no real problem and implemented many times.
> 0) are we not on windows? then don't need any of this, let macros
> expand to empty
see [4]

#if defined(DBUS_WIN)
#  if defined(DBUS_STATIC_BUILD)       [1]
# define DBUS_EXPORT
#  elif defined(dbus_1_EXPORTS)
#  define DBUS_EXPORT __declspec(dllexport)    [2]
#  else
#  define DBUS_EXPORT __declspec(dllimport)    [3]
#  endif
#define DBUS_EXPORT   [4]

> otherwise 1) are we building a static library, or are we compiling
> client code that will link to such sa static library? then don't need
> any decorations either, have macros expand to empty.
On windows static build of dbus isn't supported yet and will not make 
any sence.

If someone still needs static build support an additional macro 
DBUS_STATIC_BUILD solves this problem, see [1]. These macro has to be 
set by the dbus build system when configuring for static builds.
To avoid the need that projects have to set this macro manually when 
they use such dbus static builds this macro should be set in released 
This could be implemented later.
> otherwise, 2) is the header being read when compiling the library
> itself? then use dllexport. 
see [2] , dbus_1_EXPORTS is set by the build system when compiling dbus 
> otherwise (when compiling client code),
> then use dllimport.
see [3]
> Did I miss something? Probably.

The appended patch is complete for a shared dbus library builds 
regardless off the plattform and is prepared for static builds too. The 
related build system changes for static builds could be addressed in a 
further patch.


More information about the dbus mailing list