Building Qt Jambi on Windows using MinGW

From Qt Wiki
Revision as of 14:12, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Building Qt Jambi on Windows using MinGW

General

The following howto describes the steps neccessary to compile Qt Jambi on Windows using the MinGW development environment. It was tested on a 32bit Windows 7 installation. If you encounter any problems following it you are encouraged to seek help in the #qtjambi channel on freenode.

Prerequisites:

Note about current releases:
Current Qt releases are compiled using MinGW version 4.4, while the current official version of MinGW from http://www.mingw.org/ [mingw.org] is 4.5. Issues may arise if you try to run applications which were compiled against MinGW-4.5 with a Qt library compiled against MinGW-4.4.
Unless you have access to a MinGW version known to work with the official Qt binaries, you are encouraged to build your own Qt binaries from source. If you want to stick to the official Qt binaries you may try the MinGW-4.4 binaries provided by msysgit [code.google.com] or those shipped with the Qt SDK releases.

  • MinGW: You can download MinGW from http://www.mingw.org [mingw.org]. Follow the installation instructions there. In the rest of this howto we will assume that you have installed MinGW to C:\MinGW. If you chose a different installation destination configure your PATH accordingly in the section Adjust your CMD environment below.
  • Git (optional): You need that if you want to fetch the Qtjambi sources via git. The easiest way to achieve that is by installing Msysgit which can be downloaded from http://code.google.com/p/msysgit [code.google.com].
  • Qt: You can download Qt here: http://qt.nokia.com/ [qt.nokia.com]. The version of Qt used for this howto is Qt-4.7.1. You may have to change your PATH settings below if you chose a different version or installed it to another destination.
  • Qtjambi: Last but not least, you of course need Qtjambi itself. You have to fetch it from http://qt.gitorious.org/qt-jambi [qt.gitorious.org]. Make sure you use the latest community version, not the official version which is hopelessly outdated and not maintained anymore. You need git to fetch it: You can use msysgit [code.google.com] for it. Alternatively you can just take a source package from our website, if currently available.

Executing git clone git://gitorious.org/qt-jambi/qtjambi-4_7.git qtjambi will fetch the current development version of qtjambi into a directory called qtjambi. Now change into that directory and start with adjusting the environment.

Compile own Qt with MinGW and MSYS

1. Get Qt sources from git repo or their site
2. Open MSYS console
4. exec “make” or “mingw32-make”, which one ever is available
5. Go to eat something.

Adjust the build properties

In the root directory of Qtjambi there are two files named build.properties and buildpath.properties respectively. These two files represent the build configuration used by ant to build Qtjambi. In order for Qtjambi to compile on windows, we have to change a few settings in buildpath.properties since the default settings are geared towards compilation on linux. You have to comment in or delete (thereby effectively deactivating) the entries qtjambi.java.library.path and all those starting with qtjambi.phonon.. It is also safe to do the same to those entries describing the location of the Qt library. Those start with qt. (eg.: qt.bindir, qt.libdir). The resulting buildpath.properties configuration file – stripped of all comment lines – may look like this:

Adjust your CMD environment:

You have to at least set the QTDIR and JDK_HOME variables to point to your Qt and JDK installation respectively. The compiler suit shipped with MinGW must be in PATH so ant can find and run it. Also make sure the ant binary is in PATH or else you have to use the full path to the ant binaries in order to execute the ant command.

Below we assume that Qt is installed to C:\Qt\4.7.1, The Java JDK can be found in C:\Program Files\Java\jdk1.6.0_23 and ant has been installed to C:\Program Files\ant\ while mingw can be found in C:\MinGW (That’s the default installation path if you installed Mingw using msysgit: http://code.google.com/p/msysgit/).

The commands to set up the environment may (depending on your installation paths) look like this:

Clean Qtjambi from (possibly) existing build files

It is best to clean the root directory of qtjambi from old build-files by calling ant clean or ant distclean to have a fresh start:

Compile Qtjambi

Now start the compilation of qtjambi with the following command:

Alternatively you can use the following batch script that takes care of all this (except cleaning the build directory):

Save the script content below to a file called compile-qtjambi-win32.bat:
Note however that the script must be placed into the root directory of Qtjambi and also be executed from within that very directory.

If the compilation is successfull you will see a line similar to this:

Launching Qtjambi demo

In order to launch Qtjambi you have to set the CLASSPATH and run qtjambi like this from the Qtjambis root directory:

Note that the symbol ^ in batch scripts or in the command console on windows is used to break up long commands into several lines. You could have just as well put the entire command into a single line. We broke it up here to make it more readable.

Troubleshooting

Can’t compile Qt Jambi

If your Qt libraries are not compiled against MinGW 4.5 you won’t be able to build Qt Jambi using that version of MinGW. The standard Qt-4.7.x binaries provided by Nokia are compiled against MinGW 4.4 so you need to use that version of MinGW to compile Qtjambi. If you want to stick to your bleeding edge version of MinGW you have to compile Qt yourself using MinGW 4.5.

Can’t load Qt Jambi examples

It might happen that loading the demo app shipped with Qt Jambi fails with the following error:

This means it fails to load two vital dlls from one of the jar files listed above. This is a known bug which has already been fixed in the git repository. If you use an older version you have to workaround it by adding the location of those libs to PATH. Qt and mingw both ship those files. If you want to use the ones shipped with Qt you would have to adjust your path like so assuming Qt was installed to C:\Qt\4.7.1:
Now launching the qtjambi demo should work as expected.

Categories: