C++ - Using HunSpell 1.3.2 with Visual Studio 2010

六月ゝ 毕业季﹏ 提交于 2019-12-19 04:22:51

问题


My goal is to create a simple Win32 Console application that uses HunSpell to spell-check a word the user has entered. I tried to follow this codeproject tutorial which is for Visual Studio 2008 and HunSpell 1.2.1.

I don’t want to use the provided code, since I intend to write my own. Furthermore I want to add HunSpell as a dll, not as a static library.

Following are the steps I took:

  1. Created a Win32 console (empty) project with the name myproject.
  2. Downloaded HunSpell 1.3.2 from SourceForge.org.
  3. Copied hunspell-1.3.2\src\hunspell and win_api to myproject\myproject\HunSpell-Src
  4. Added and converted project libhunspell myproject\myproject\HunSpell-Src\win-api\libhunspell.vcproj to the solution.
  5. Made my debug build use debug_dll and my release build release_dll of libhunspell in the Configuration Manager.
  6. Rebuilt the libhunspell project, libhunspell.dll is generated in debug_dll and release_dll folders respectively.
  7. Made my console project depend on libhunspell. (Added reference to libhunspell)
  8. Copied dictionary files en_US.aff & en_US.dic to myproject\myproject\HunSpell-Dic after downloading them from SourceForge.org.

I can’t figure out how/where to add the processor define HSPELLEDIT_DLL that is mentioned in the codeproject tutorial.

Following the steps listed under “To use the functionality from the class library in the console application” on MSDN didn’t changed the result.

I want to test it with a program like this:

#include <iostream>
#include "HunSpell-Src/win_api/hunspelldll.h"

using namespace std;

void main()
{
    void *spellObj = hunspell_initialize("HunSpell-Dic\\en_us.aff", "HunSpell-Dic\\en_us.dic");

    char str[60];

    cin >> str;

    int result = hunspell_spell(spellObj, str);

    if(result == 0)
        cout << "Spelling error!";
    else
        cout << "Correct Spelling!";

    hunspell_uninitialize(spellObject);
}

VS produces the following error message if I try to compile it:

myproject\myproject\hunspell-src\win_api\hunspelldll.h(34): fatal error C1083: Cannot open include file: 'hunspell.hxx': No such file or directory

Hunspell.hxx is present in myproject\myproject\HunSpell-Src\hunspell. IntelliSense marks the #include "hunspell.hxx" as an error while the tab hasn’t focus with the message “Error: cannot open source file hunspell.hxx”, but after giving focus to it the error disappears.

Thank you for your help.


回答1:


The preprocessor definition, HSPELLEDIT_DLL, is not needed unless you are going to actually use the codeproject author's custom control. In the case you want to define it (or other preprocessor definitions) refer to /D (Preprocessor Definitions).

Your path strings need to be double \\ instead of single \ escaped and you have some compile issues:

#include <iostream>
#include "HunSpell-Src/win_api/hunspelldll.h"

using namespace std;

void main()
{
    Hunspell *spellObj = (Hunspell *)hunspell_initialize("HunSpell-Dic\\en_us.aff", "HunSpell-Dic\\en_us.dic");
//  ^change * type        ^cast returned void* to type that will be used later

    char str[60];

    cin >> str;

    int result = hunspell_spell(spellObj, str);

    if(result == 0)
        cout << "Spelling error!";
    else
        cout << "Correct Spelling!";

    hunspell_uninitialize(spellObj /*SpellObject is undefined*/);
//                        ^use correct variable
}

For Hunspell.hxx, you need to tell your project how to find it. To do this, open your project settings and and the path to Hunspell.hxx to 'Additional Include Directories' under Configuration Properties > C++ > General. Refer to /I (Additional Include Directories).

Based on your directory structure:

  • Your Project > Properties > Configuration Properties > C++ > General > 'Additional Include Directories' should look like: .\HunSpell-Src\hunspell;%(AdditionalIncludeDirectories)

  • Your Project > Properties > Configuration Properties > Linker > General > 'Additional Library Directories' should look like: .\Debug_dll\libhunspell;%(AdditionalLibraryDirectories)

You will also need to copy myproject\myproject\Debug_dll\libhunspell\libhunspell.dll to your projects output directory (.\Debug) or your exe will not be able to find it.



来源:https://stackoverflow.com/questions/9703520/c-using-hunspell-1-3-2-with-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!