Build on windows

From VipsWiki

(Difference between revisions)
Jump to: navigation, search

Revision as of 17:57, 26 June 2006

Contents

Building VIPS and nip on Windows with MinGW

These instructions work for VIPS 7.10 and 7.11. vips8 is a slightly different beast.

You might also be interested in build instructions for Evolution and build instructions for GTK.

This is not straightforward, allow a day. I'd only bother with this if you really need to make Windows binaries. If you just want to build it to try it out it's honestly much simpler to install linux in a spare partition and compile there.

Once you have a working build, you need to package for distribution. Package on windows explains how.

Disclaimer: I wrote this page over a period of several days with lots of failure and backtracking. I tried to keep careful notes but I may have made a mistake ... I could test these instructions by wiping my machine and reinstalling from scratch, but just the thought makes me feel ill. Also, I did this on a machine I had admin rights on, I don't know if this would work if you have a limited user account.

If anyone gets a working build environment from reading this, please add a note with the good news.

Update: Simon claims success from following this page!

Installing MinGW / MSYS

The MingW website has a bunch of stuff; you might find it helpful to read that first. Then get the files you need: from the MinGW download area grab (current versions on 2/8/05, there might be better ones available by the time you try):

  • MinGW-4.1.1.exe
  • MSYS-1.0.10.exe
  • msysDTK-1.0.1.exe
  • gdb-5.2.1-1.exe (not required, but useful)

Also get bison-2.0-MSYS.tar.gz and untar it to / (not to /mingw!!).

Installing dependencies

Now you need a huge list of dependent libraries. In order, install:

glib/gtk

There are a large set of windows binaries for glib/gtk on Tor Lillqvist's download page for windows Gimp developers.

I installed these to /usr/local. Do not install to / or to /usr! MSYS treats these directories with special magic and your install will fail. You could probably also install to /mingw, but it seemed cleaner to keep them apart.

I added this to the end of /etc/profile:

# need to tell mingw gcc about /usr/local
export C_INCLUDE_PATH=/usr/local/include
 
# tell configure to add /usr/local/lib to link lines
export LDFLAGS="-L/usr/local/lib"

Then of course either source /etc/profile or restart MSYS.

Then install in order:

  • current versions of glib, atk, pango and gtk: you need the developer versions as well as the libraries (I used glib-2.6.6, atk-1.9.0, pango-1.8.2, gtk+-2.6.9)
  • pkg-config: again, install to /usr/local!
  • iconv, gettext-runtime, gettext-tools
  • you should now be able to test pkg-config. Try pkg-config --list-all and check that you get a sensible listing of packages (and not an error message)
  • follow Tor's links and get the zip files for jpeg, png and tiff. Get both the bin and the lib zips, don't get the .exe installers. png needs adjusting, see the section below.
  • freetype, both developer and runtime
  • zlib: at the time of writing, Tor links to http://www.zlib.net/zlib122-dll.zip, which is the previous version and has been deleted. Get zlib123-dll.zip instead. Also, this does not name libraries in a way that mingw understands. I copied zdll.lib to z.lib to get linking working
  • fontconfig, runtime and developer packages
  • expat: just pull out xmlparse.dll and xmltok.dll and put them in /usr/local/bin
  • libexif, runtime and developer
  • libxml2: get libxml2.dll from the linked package, but you need to build your own static version too, see below
  • liblcms: don't get this, there's no developer package, you have to build it yourself, see below

flex

I got a flex binary from gnuwin32. You need the bin and the lib zips.

Copy flex.exe from the bin zip to /usr/local/bin and libfl.a from the lib zip to /usr/local/lib.

libxml2

It seems linking against dynamically-linked libxml2 is broken on mingw, due to problems with xmlFree() being an exported pointer to a function, rather than an actual function. xmlFree() is defined in the .dll, but does not appear in the .lib, very mysterious.

I downloaded 2.6.22 and built with:

CFLAGS="-mms-bitfields -Wall -O2 -DLIBXML_STATIC" ./configure --disable-shared
make
make install

You need the -DLIBXML_STATIC on anything that compiles against the static libxml.a. To prevent it getting forgotten by mistake, I added it to Cflags in /usr/local/lib/libxml-2.0.pc after install. Also, libxml seems to forget to add the windows sockets library -lws2_32 to Libs.

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
modules=0
  
Name: libXML
Version: 2.6.22
Description: libXML library version2.
Requires:
Libs: -L${libdir} -lxml2 -lz -liconv -lws2_32
Cflags: -DLIBXML_STATIC -I${includedir}/libxml2

Perl

MSYS comes with Perl, but I just can't see how to get XML::Parser working in the MSYS one. Install ActiveState Perl instead and save hours of pain.

I moved MSYS's /bin/*perl* to /bin/msys-perl to make sure I didn't invoke the MSYS one by mistake, then did mkdir /perl and added the activestate Perl area to /etc/fstab, mounting on /perl. I also moved /lib/perl5 to /lib/msys-perl5 to hide it.

Sadly now perl scripts need to start with #!/perl/bin/perl and all need editing. Perhaps someone can suggest a clever way around this?

Little CMS

I can't find a recent lcms which works well with mingw. You need to build yourself. Download the unix sources, configure with

CFLAGS="-mms-bitfields -Wall -O2" ./configure

make and make install. For version 1.14 I found I had to patch lcms.h. Change

typedef unsigned int DWORD, *LPDWORD;

to

typedef unsigned long DWORD, *LPDWORD;

to avoid conflicts with mingw's windows.h.

Image Magick

Annoyingly, the ImageMagick binary depends on registry entries to find parts of itself, so you can't use it to build standalone applications. You have to build your own image magick from source.

I downloaded version 6.2.5-4. I had to patch magick/nt-base.c like this:

*** nt-base.old Mon Nov 14 11:31:22 2005
--- nt-base.c   Mon Nov 14 11:41:11 2005
***************
*** 1419,1424 ****
--- 1419,1433 ----
  %      is to be loaded.
  %
  */
+ static const char *getsearchpath( void )
+ {
+ #ifdef HasLTDL
+   return lt_dlgetsearchpath();
+ #else /*!HasLTDL*/
+   return lt_slsearchpath;
+ #endif /*HasLTDL*/
+ }
+ 
  MagickExport void *NTOpenLibrary(const char *filename)
  {
  #define MaxPathElements  31
***************
*** 1429,1435 ****
    int
      index;
  
!   register char
      *p,
      *q;
  
--- 1438,1444 ----
    int
      index;
  
!   register const char
      *p,
      *q;
  
***************
*** 1444,1455 ****
  
    mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
    handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
!   if ((handle != (void *) NULL) || (lt_slsearchpath == (char *) NULL))
      {
        SetErrorMode(mode);
        return(handle);
      }
!   p=lt_slsearchpath;
    index=0;
    while (index < MaxPathElements)
    {
--- 1453,1464 ----
  
    mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
    handle=(void *) LoadLibraryEx(filename,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
!   if ((handle != (void *) NULL) || (getsearchpath() == (char *) NULL))
      {
        SetErrorMode(mode);
        return(handle);
      }
!   p=(char*)getsearchpath();
    index=0;
    while (index < MaxPathElements)
    {
***************
*** 1798,1807 ****
--- 1807,1820 ----
  */
  MagickExport int NTSetSearchPath(const char *path)
  {
+ #ifdef HasLTDL
+   lt_dlsetsearchpath(path);
+ #else /*!HasLTDL*/
    if (lt_slsearchpath)
      lt_slsearchpath=(char *) RelinquishMagickMemory(lt_slsearchpath);
    if (path != (char *) NULL)
      lt_slsearchpath=AcquireString(path);
+ #endif /*HasLTDL*/
    return(0);
  }

I posted this patch to the magick list, maybe later versions won't need it. Then configure and build with:

CFLAGS="-mms-bitfields -Wall -O2" ./configure --disable-shared --without-perl
make
make install

ImageMagick shared libs seem a bit broken with mingw. And PerlMagick didn't build right for me, so I turned it off.

Finally, the ImageMagick.pc file that gets installed seems to be missing dependent libs. I typed:

Magick-config --libs 

then appended the output to the Libs line in /usr/local/lib/pkgconfig/ImageMagick.pc.

pangoft2

pangoft2.pc needs tweaking for the install location of your freetype and fontconfig packages. In /usr/local/lib/pkgconfig/pangoft2.pc, I swapped:

Cflags: -I${includedir}/pango-1.0 -I/path/to/your/fontconfig/headers -I/path/to/your/freetype/headers

for

Cflags: -I${includedir}/pango-1.0 -I/usr/local/include -I/usr/local/include/freetype2

libpng

I found I had to tweak the libpng.pc from the 1.2.8 distribution. It references a libpng12.lib which doesn't exist: the distribution only contains libpng.lib and libpng13.lib.

In fact libpng.lib and libpng13.lib are identical, so it doesn't matter which points where. I edited libpng.pc to be:

prefix=/usr/local/
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${exec_prefix}/include

Name: libpng
Description: Loads and saves PNG files
Version: 1.2.8
Libs: -L${libdir} -lpng -lz -lwsock32 -lole32 -luuid
Cflags: -I${includedir}

There was also a strange -lgw32c in the libs line which caused problems, I removed it and got a clean compile.

fftw

I couldn't find a good set of windows binaries, but it's a very easy package to build, so make your own.

I downloaded fftw-3.0.1.tar.gz and did

CFLAGS="-mms-bitfields -Wall -O2" ./configure
make
make install

You don't get a DLL, just a static lib, but it doesn't matter.

OpenEXR (needed for 7.11 only)

OpenEXR is partly in C++ and is rather sensitive to STL version mismatches. Download OpenEXR-1.2.2 and configure with:

CFLAGS="-mms-bitfields -O2" CXXFLAGS="-mms-bitfields -O2" CPPFLAGS="-I/usr/local/include -DPLATFORM_WINDOWS" LDFLAGS="-L/usr/local/lib" ./configure
make
make install

Again, you only get a static library, but it doesn't really matter.

VIPS

Configure with:

CFLAGS="-mms-bitfields -Wall -O2" ./configure

Or for vips-7.11, use:

./configure --disable-shared

check configure output carefully, especially libxml2, Magick and lcms. Then

make
make install

You may see some annoying warnings about libintl_printf; ignore them.

Currently, plugins are still broken with win32. Patch in the source of any required plugins.

nip2

This should now be easy, since the tricky dependencies are in VIPS.

CFLAGS="-mms-bitfields -Wall -O2" ./configure
make
make install

Then start nip2 to test, and load one of the example workspaces.

Packaging

Once you have a working build, you need to package for distribution. Package on windows explains how.

Personal tools