Compiling QtDBus for Windows…

I keep needing to do this. Each time I do, I have to rediscover how to do it.

Worse, I’m doing it slightly differently each time.

For interested parties, here’s what I just did for Qt 4.7.1. Worked for Qt 4.7.0, too.

I’m using MinGW, cmake, libexpat, and of course Qt. To begin, you need to build dbus itself for Windows, and then you can rebuild

  1. Make sure you have MinGW installed and correctly configured. Its bin directory should be in your path.
  2. Download cmake. Install.
  3. Download and install libexpat from suggested in the dbus documentation). You’ll want the lib archive. You’ll need the include directory no matter what for when you build QtDBus. Unpack these zips to C:\Program Files\win32libs.
  4. Grab dbus from the repository, put it in c:\dbus-1.4.0.
  5. Edit dbus-1.4.0\cmake\CMakeLists.txt, add
    set(LIBEXPAT_LIBRARIES "C:/Program Files/win32libs/lib/libexpat.lib")
    set(LIBEXPAT_INCLUDE_DIR "C:/Program Files/win32libs/include")


  6. Start a Windows Command Prompt
  7. mdkir c:\dbus && cd c:\dbus
  8. cmake -G "MinGW Makefiles" ..\dbus-1.4.0\cmake -DDBUS_USE_EXPAT=on
  9. mingw32-make
  10. Add c:\dbus\bin to your path.
  11. Edit c:\qt\4.7.1\src\dbus\
    win32 {
        wince*:LIBS_PRIVATE += -lws2
        else:LIBS_PRIVATE += -lws2_32 \
        -ladvapi32 \
        -lnetapi32 \
        CONFIG(debug, debug|release):LIBS_PRIVATE += -ldbus-1 -Lc:/dbus/bin
        else:LIBS_PRIVATE += -ldbus-1 -Lc:/dbus/bin
        INCLUDEPATH += c:/dbus-1.4.0 c:/dbus
  12. You don’t need to build QtDBus separately to begin with the way I do here (step 13) — but it’s much faster to do that and know it’s working than it is to start the configure / mingw32-make step, walk away, and find out an hour later that it died someplace in the middle because you messed up the path to dbus or something.

  13. Start a Qt Command Shell.
  14. cd c:\qt\4.7.1\src\dbus && qmake && mingw32-make
  15. cd ..\.. && configure -dbus && mingw32-make

Your mileage may vary. I seem to remember fixing at least one compilation error in dbus at one point, but don’t remember precisely where or why. It wasn’t hard to do, though — something about a missing argument.

Leave a Reply