首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++ -在Visual 2010中使用HunSpell 1.3.2

C++ -在Visual 2010中使用HunSpell 1.3.2
EN

Stack Overflow用户
提问于 2012-03-14 14:07:01
回答 1查看 4.1K关注 0票数 2

我的目标是创建一个简单的Win32控制台应用程序,它使用HunSpell拼写检查用户输入的单词。我试着遵循Visual 2008和本代码项目教程 1.2.1的本代码项目教程

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

以下是我所采取的步骤:

  1. 创建一个名为myproject的Win32控制台(空)项目。
  2. 从HunSpell下载了SourceForge.org 1.3.2。
  3. hunspell-1.3.2\src\hunspellwin_api复制到myproject\myproject\HunSpell-Src
  4. 向解决方案添加和转换项目libhun拼写myproject\myproject\HunSpell-Src\win-api\libhunspell.vcproj
  5. 让我的调试生成使用debug_dll,并在Configuration中使用libhun拼写的发布构建release_dll。
  6. 重新构建libhun拼写项目,libhunspell.dll分别在debug_dll和release_dll文件夹中生成。
  7. 让我的控制台项目依赖于libhun拼写。(增加了对libhun拼写的引用)
  8. myproject\myproject\HunSpell-Dic下载字典文件en_US.aff & en_US.dic到SourceForge.org。

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

按照“在控制台应用程序中使用类库中的功能”下面列出的步骤,MSDN上没有更改结果。

我想用这样的程序来测试它:

代码语言:javascript
复制
#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会产生以下错误消息:

代码语言:javascript
复制
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\hun拼写中。IntelliSense将#include "hunspell.hxx“标记为一个错误,而选项卡没有显示”error :unOpenSourceFilehunspell.hxx“消息,但是在给予焦点之后,错误就消失了。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-14 14:43:58

除非您实际使用codeproject的自定义控件,否则不需要预处理器定义HSPELLEDIT_DLL。在要定义它的情况下(或其他预处理器定义),请参考/D (前处理器定义)

您的路径字符串需要为double \而不是单\转义,并且您有一些编译问题:

代码语言:javascript
复制
#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,您需要告诉您的项目如何找到它。为此,在Configuration > C++ > General下打开项目设置和通往C++的“附加包含目录”的路径。请参阅/I (附加包含目录)

基于,您的目录结构:

  • 您的Project > Properties > Configuration Properties > C++ > General > 'Additional Include Directories'应该是:.\HunSpell-Src\hunspell;%(AdditionalIncludeDirectories)
  • 您的Project > Properties > Configuration Properties > Linker > General > 'Additional Library Directories'应该是:.\Debug_dll\libhunspell;%(AdditionalLibraryDirectories)

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9703520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档