我的目标是创建一个简单的Win32控制台应用程序,它使用HunSpell拼写检查用户输入的单词。我试着遵循Visual 2008和本代码项目教程 1.2.1的本代码项目教程。
我不想使用提供的代码,因为我打算编写自己的代码。此外,我希望添加HunSpell作为一个dll,而不是作为一个静态库。
以下是我所采取的步骤:
我不知道如何/在哪里添加处理器定义代码项目教程中提到的HSPELLEDIT_DLL。
按照“在控制台应用程序中使用类库中的功能”下面列出的步骤,MSDN上没有更改结果。
我想用这样的程序来测试它:
#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会产生以下错误消息:
myproject\myproject\hunspell-src\win_api\hunspelldll.h(34): fatal error C1083: Cannot open include file: 'hunspell.hxx': No such file or directoryHunspell.hxx存在于myproject\myproject\hunspell-Src\hun拼写中。IntelliSense将#include "hunspell.hxx“标记为一个错误,而选项卡没有显示”error :unOpenSourceFilehunspell.hxx“消息,但是在给予焦点之后,错误就消失了。
谢谢你的帮助。
发布于 2012-03-14 14:43:58
除非您实际使用codeproject的自定义控件,否则不需要预处理器定义HSPELLEDIT_DLL。在要定义它的情况下(或其他预处理器定义),请参考/D (前处理器定义)。
您的路径字符串需要为double \而不是单\转义,并且您有一些编译问题:
#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将无法找到它。
https://stackoverflow.com/questions/9703520
复制相似问题