C ++ - 使用HunSpell 1.3.2与Visual Studio 2010

C ++  - 使用HunSpell 1.3.2与Visual Studio 2010

问题描述:

我的目标是创建一个简单的Win32控制台应用程序,使用HunSpell拼写检查用户输入的字。
我试图关注这个codeproject教程 a>这是为Visual Studio 2008和HunSpell 1.2.1。

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.

我不想使用提供的代码,因为我打算自己写。
此外,我想将HunSpell添加为dll,而不是作为静态库。

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.

以下是我采取的步骤:


  1. 创建一个名为myproject的Win32控制台(空)项目。

  2. 从SourceForge.org下载HunSpell 1.3.2。 li>
  3. hunspell-1.3.2 \src\hunspell win_api 复制到 myproject\myproject\HunSpell-Src

  4. 添加并转换了项目libhunspell myproject\myproject\HunSpell-Src\win-api\libhunspell.vcproj

  5. 在配置管理器中使用debug_dll和我的发行版libhunspell构建release_dll。

  6. 重新构建libhunspell项目, em> libhunspell.dll 分别在debug_dll和release_dll文件夹中生成。

  7. 使我的控制台项目依赖于libhunspell。 (添加对libhunspell的引用)

  8. 复制字典文件en_US.aff& en_US.dic到从SourceForge.org下载后的 myproject\myproject\HunSpell-Dic

  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.

我不知道如何/在哪里添加处理器定义HSPELLEDIT_DLL在代码项目教程中提到。

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

按照使用功能从控制台应用程序中的类库,位于 MSDN 没有改变结果。

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会产生以下错误消息:

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存在于myproject \ myproject\HunSpell-Src\hunspell。 IntelliSense将#includehunspell.hxx标记为错误,而标签没有焦点时显示消息错误:无法打开源文件hunspell.hxx,但在给予焦点后,错误消失。

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.

感谢您的帮助。

不需要预处理器定义HSPELLEDIT_DLL除非你要使用codeproject作者的自定义控件。如果要定义它(或其他预处理器定义),请参阅 / D(预处理程序定义)

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
}

对于Hunspell.hxx需要告诉你的项目如何找到它。为此,打开您的项目设置和Hunspell.hxx的路径到配置属性> C ++>常规下的其他包括目录。请参阅 / I(其他包括目录)

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:


  • 您的 Project>特性>配置属性> C ++>一般> 'Additional Include Directories'应类似于: .\HunSpell-Src\hunspell;%(AdditionalIncludeDirectories)

您的 Project>属性>配置属性>接头>一般> 其他库目录应如下所示: .\Debug_dll\libhunspell;%(AdditionalLibraryDirectories)

您还需要复制 myproject\myproject\Debug_dll\libhunspell\libhunspell.dll 到您的项目输出目录(.\Debug)或您的exe将无法找到它。

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.