Integrating your application with Enchant – Part 1

Enchanté
Welcome to the first in a series of articles exploring how to integrate the spell checking library Enchant into your Visual C++ applications.

I will be integrating Enchant with the next release of NoteKeeper, which I am currently maintaining in an old version of MSVC and also developing a new version from scratch. Thus I will be using the following configurations.

  • Visual C++ 6 SP6 with STLPort 5.1.5, Multithreaded DLL
    (cl.exe v12.00.8804, link.exe v6.00.8447)
  • Visual C++ 9 SP1, Multithreaded DLL
    (cl.exe v15.00.30729.01, link.exe v9.00.30729.01)

Enchant isn’t actually a spell checking library in itself; it is more accurately described as a compatibility layer across the existing spell checking libraries (aspell, pspell, and myspell being amongst the most notable).

Part 1 – Building the support libraries

In this article we will start by building the support libraries required by Enchant. Subsequent articles will deal with building Enchant itself and integrating it with NoteKeeper. This is illustrated by the lovely graphic below.

Enchant Integration Overview

Prerequesites

Before we begin, you should have the following installed on your system.

The Support Libraries

Download the source code packages of the following libraries. All should be available from your nearest GNU mirror.

Note: Enchant only requires the libintl part of the gettext library.

Unpack the libraries

Unpack the libraries into the following directory structure. Obviously your platform-level directories (such as msvc6) should be named appropriately for your own platform.

  • lib
    • msvc6
      • gettext-0.14.5
      • glib
      • libiconv-1.9.1
    • msvc9
      • gettext-0.14.5
      • glib
      • libiconv-1.9.1

Note: The glib-2.18.3 directory has been renamed to glib.
Enchant Dependency Build Order

Build Overview

There is a set build order because:

  1. glib depends on libiconv and libintl (part of gettext);
  2. libiconv and libintl are co-dependent.

The build order is as follows:

  1. libiconv, without NLS support
  2. libintl
  3. libiconv, with NLS support
  4. libglib and libgmodule (part of glib)

Build!

The build instructions below have been tested with both MSVC6 and MSVC9. There are a few differences in procedure between the different compiler versions and these have been highlighted where required.

You will need to substitute the version of your compiler in the commands below, so where it is written C:\usr-msvcX, I would substitute this as C:\usr-msvc6 for MSVC6 and C:\usr-msvc9 for MSVC9.

To build debug versions, use MFLAGS=-MDd and PREFIX=C:\usr-msvcX-debug, and add DEBUG=1.

Build libiconv

A patch is required for MSVC9 which disables the use of VPRINTF. This is a workaround to avoid the failed compilation of the Unix variant of va_start. The patch can be downloaded from here.

In the lib\msvcX\libiconv-1.9.1 directory:

  • MSVC9 ONLY: patch -i config-msvc9.diff
  • nmake -f Makefile.msvc NO_NLS=1 DLL=1 MFLAGS=-MD PREFIX=C:\usr-msvcX
  • nmake -f Makefile.msvc NO_NLS=1 DLL=1 MFLAGS=-MD PREFIX=C:\usr-msvcX install

Build libintl

A patch is required for MSVC9 which changes a couple of #define’d tokens for their explicit values. The compiler seemed to get confused with the nested switch statements in localename.c. The patch can be downloaded from here.

In the lib\msvcX\gettext-0.14.5\gettext-runtime directory:

  • nmake -f Makefile.msvc config.h

In the lib\msvcX\gettext-0.14.5\gettext-runtime\intl directory:

  • MSVC9 ONLY: patch -i localename-msvc9.diff
  • nmake -f Makefile.msvc DLL=1 MFLAGS=-MD PREFIX=C:\usr-msvcX
  • nmake -f Makefile.msvc DLL=1 MFLAGS=-MD PREFIX=C:\usr-msvcX install

Rebuild libiconv

In the lib\msvcX\libiconv-1.9.1 directory:

  • nmake -f Makefile.msvc DLL=1 MFLAGS=-MD PREFIX=C:\usr-msvcX clean
  • nmake -f Makefile.msvc DLL=1 MFLAGS=-MD PREFIX=C:\usr-msvcX
  • nmake -f Makefile.msvc DLL=1 MFLAGS=-MD PREFIX=C:\usr-msvcX install

Build libglib and libgmodule

In the lib\msvcX\glib directory:

  • nmake -f Makefile.msc config.h glibconfig.h

In the lib\msvcX\glib\build\win32\dirent directory:

  • nmake -f makefile.msc INTL=C:\usr-msvcX

In the lib\msvcX\glib\glib directory:

  • nmake -f Makefile.msc INTL=C:\usr-msvcX
  • copy glib-2.0.lib c:\usr-msvcX\lib
  • copy libglib-2.0-0.dll c:\usr-msvcX\bin

In the lib\msvcX\glib\gmodule directory:

  • nmake -f Makefile.msc INTL=C:\usr-msvcX
  • copy gmodule-2.0.lib c:\usr-msvcX\lib
  • copy libgmodule-2.0-0.dll c:\usr-msvcX\bin

To Be Continued…

In the next part we will build the core enchant library (libenchant), the providers and the test programs.

Acknowledgements

Thanks to Dom Lachowicz for creating Enchant and for the Win32 build instructions he has provided (see Build.win32.readme in the Enchant library).

by Alex Paterson (alex@tolon.co.uk) Copyright © 2008. Permission is granted to distribute this article without fee as long as the copyright notice remains intact and any modifications are clearly indicated as such.

3 thoughts on “Integrating your application with Enchant – Part 1”

  1. Are you planning on eventually supplying an installable spell checking system? I’m not a programmer, and don’t really feel I have the time to jump through hoops to have spell checking available.

    Based on your help file I expected to come here and just download that language file I need, install it, and be able to spell check my work.

    BTW, I think your link on the page should include something that says ‘spell checking support’ so it’s easy to get here. I had to click all the links to find this because I had no idea what ‘Enchant’ is.

    Nice program and I’d really like to see and do beta testing on a more mature version, or even this one if you’d like the feedback from someone who is interested in converting to NoteKeeper as his primary word processor.

    Keep up the good work!

  2. Paul NcAlsen :

    Based on your help file I expected to come here and just download that language file I need, install it, and be able to spell check my work.

    Sorry for the mix-up, Paul. Spell checking is currently supported in Tolon NoteKeeper, but it can be a bit unreliable. I am re-writing it for version 0.10, hence this article.
    I’ve added the spell checking language packages from the old site onto the download page, so you can now get them from here.


    Keep up the good work!

    Thanks!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.