Important: Please read the Qt Code of Conduct -

Dynamically linking to Hunspell

  • I have a project in which I would like to dynamically link to the Hunspell library so my app can have spell-check. The only problem is, I have no idea how to do it. I'm more familiar with the concept in Visual Studio/ C# but I've never done it in a Qt/C++ app before. I did some research and I learned how to put a reference to the library in my project file but I still haven't figured out how to #include it in the classes that need it (the library never shows up in that list Qt Creator offers for includes). Hopefully it's the correct library; It's the file from Ubuntu's "libhunspell-1.3-0" package.

    I intend to release on Linux and Windows (and maybe Mac at some point, if I ever find a way to maintain the app on that platform). I know most Linux distros have ready-made Hunspell libraries in their repositories. I hope I can use those to prevent any potential distribution/licensing pitfalls. On Windows I'll probably have to roll my own DLL from source but hopefully the process of linking against it will be the same.

    This part of Qt programming is completely new to me so I would really appreciate any info/help you guys can give me. Thanks in advance.

  • Lifetime Qt Champion


    First thing to do is to install the hunspell dev package if you didn't do that already.

    If you still can't get the include working after that, check where the hunspell includes can be found and add the path to INCLUDEPATH.

    For the linking part, it should look like:

    @LIBS += -lhunspell-1.3@

    If for any reason the library can't be found:

    @LIBS += -L/path/to/where_libhunspell.so_can_be_found@

    For the Mac port, you can have hunspell from e.g. macport or brew, you'll have to adapt some path but compiling the application itself should not be problematic. However, the deployment is a bit more complex (but assisted by e.g. macdeployqt)

    On windows, again, most of the time it will be a question of path to correct, the deployment is also less easy but not overly complicated, you have a fine "wiki entry": to help you (if curious about gory details, take a look at Qt's documentation)

    Hope it helps

  • Thanks, that definitely helped.

    I got this working on Ubuntu/other distros in the Debian family but I'm having trouble with Fedora b/c there seems to be no hunspell-dev equivalent package on that distro (just dictionaries for various languages). I need a package that has both headers and libraries in it. If I can't find a solution, I may have to abandon Fedora support. It's a real shame but I don't know if I can make this work on every flavor of Linux out there, especially if there aren't packages I can use as dependencies.

    In the meantime, I'm going to start working on the Windows part.

  • Lifetime Qt Champion

    You should ask the Fedora guys about their support for hunspell/hunspell dev package

  • On Fedora you have 'hunspell-devel'
    $ sudo yum install hunspell-devel

  • On Fedora you have 'hunspell-devel'
    $ sudo yum install hunspell-devel

Log in to reply