Compiling a Hunspell DLL, step by step

[Update (18/8/10): since I posted this, some revisions to the Hunspell source in the meantime might make it easier to just use the libhunspell project file in the win_api sub-directory. As per my comment in response to Arnold below, this project in the v1.2.11 release builds fine for me ‘as is’.]

As I got asked, I thought I might as well make a separate post out of it, so here goes. To compile a new Hunspell DLL, you could do the following:

  1. Make sure you have a suitable C++ compiler at the ready. I’ve no idea about C++Builder, but Visual C++ Express does the job fine, and it’s free.
  2. Make sure you have something like the (open source) 7-ZIP installed so you can open a compressed tarball file (.tar.gz).
  3. Download the Hunspell source from Hunspell’s Sourceforge homepage.
  4. Extract said source to a suitable directory. If you inspect the extracted files, you’ll come across more than one MSVC project file — specifically, you should be able to find one for MSVC 6 in src\hunspell (hunspell.dsp) and a MSVC 2005 project group (‘solution’) in src\win_api (Hunspell.sln, hunspell.vcproj, libhunspell.vcproj, testparser.vcproj). Basically, Hunspell is a C++ library, though at some point, a new DLL project file with C exports (the one in win_api) was added to the standard distribution to make using Hunspell with (e.g.) Delphi simpler. Later still however, a C interface with slightly different signatures was added to the main source. Consequently, it doesn’t really matter which project file you choose — my wrapper supports DLLs produced by either. Also, while only the win_api project file is set to create a DLL by default, you’ll still have to fiddle about with it before getting it to compile, and once done, it will create a slightly larger DLL compared to the other one.
  5. That in mind, load up MSVC Express, go to File|Open|Project/Solution…, and find your way to src\hunspell\hunspell.dsp.  Accept the resulting prompt to convert the project file to the newest format.
  6. Go to Project|Add Existing Item, and from src\hunspell, choose every .cxx and .hxx file. I also suggest adding Hunspell.rc from src\win_api too.
  7. Go to Project|Properties, select Configuration Properties in the tree view, then All Configurations in the Configurations combo box (the latter lies directly above the tree view). Next, change Configuration Type to Dynamic Library (.dll), before selecting  C/C++ in the tree view and setting Additional Include Directories to ..\win_api.
  8. You should now be able to build the project, which will produce hunspell.dll under src\hunspell\Debug. To create a release build, select the Release configuration (most easily from the combo box immediately to the right of the ‘run’ toolbar button), and rebuild. This should cause another hunspell.dll to be created, only this time under src\hunspell\Release.
Arnold

2 thoughts on “Compiling a Hunspell DLL, step by step

  1. Just found your post and tried to compile the hunspell.dll with MSVC 2008 Express as per the instructions, but I am getting all sorts of errors such as
    >c:\pkg\c\hunspell-1.2.11\src\hunspell\affixmgr.cxx(18) : warning C4273: ‘AffixMgr::AffixMgr’ : inconsistent dll linkage
    1> c:\pkg\c\hunspell-1.2.11\src\hunspell\affixmgr.hxx(105) : see previous definition of ‘{ctor}’
    1>c:\pkg\c\hunspell-1.2.11\src\hunspell\affixmgr.cxx(116) : warning C4273: ‘AffixMgr::~AffixMgr’ : inconsistent dll linkage
    1> c:\pkg\c\hunspell-1.2.11\src\hunspell\affixmgr.hxx(107) : see previous definition of ‘{dtor}’
    1>c:\pkg\c\hunspell-1.2.11\src\hunspell\affixmgr.cxx(251) : warning C4273: ‘AffixMgr::parse_file’ : inconsistent dll linkage
    1> c:\pkg\c\hunspell-1.2.11\src\hunspell\affixmgr.hxx(205) : see previous definition of ‘parse_file’

    I’m still working my way through this, hoping that somehow I have included too much, but as far as I can see, I followed you instruction and included all hxx and cxx files.
    TIA for your post and any possible pointers as to what I might have missed

    • I see there’s been one or more new Hunspell revisions released since I posted, and you’re attempting to use one of them (v1.2.11). Having just downloaded it myself however, using the ‘solution’ file in the winapi sub-directory produced a working project group without having to do anything – I built the libhunspell project to get a DLL. If you want a DLL compiled using the ‘release’ rather than ‘debug’ configuration (as you probably will), just toggle the setting via the combo box in the middle of the main toolbar and rebuild; this then produces a 334KB DLL for me.

Leave a comment