C++-在Visual Studio 2010中使用HunSpell 1.3.2
C++ - Using HunSpell 1.3.2 with Visual Studio 2010
我的目标是创建一个简单的Win32控制台应用程序,该应用程序使用HunSpell来拼写检查用户输入的单词。我试着遵循这个代码项目教程,它适用于Visual Studio 2008和HunSpell 1.2.1。
我不想使用提供的代码,因为我打算自己编写代码。此外,我想将HunSpell添加为dll,而不是静态库。
以下是我采取的步骤:
- 创建了一个名为myproject的Win32控制台(空)项目
- 已从SourceForge.org下载HunSpell 1.3.2
- 复制hunspell-1.3.2\src\hunspell和win_api到myproject\myproject\hunspell src
- 添加并转换了项目libhunspellmyproject\myproject\HunSpell Src\win-api\libhunspel.vcproj解决方案
- 在Configuration Manager中使用libhunspell的debug_dll和发布版本release.dll进行调试构建
- 重建了libhunspell项目,分别在debug_dll和release.dll文件夹中生成libhunspill
- 使我的控制台项目依赖于libhunspell。(添加了对libhunspell的引用)
- 复制的词典文件en_US.aff&从SourceForge.org下载en_US.dic后,将其转换为myproject\myproject\HunSpell dic
我不知道如何/在哪里添加处理器定义代码项目教程中提到的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,它会产生以下错误消息:
myprojectmyprojecthunspell-srcwin_apihunspelldll.h(34): fatal error C1083: Cannot open include file: 'hunspell.hxx': No such file or directory
Hunspell.hxx存在于myproject\myproject\Hunspell Src\Hunspell中。IntelliSense将#include"hunspell.hxx"标记为错误,而选项卡没有聚焦,并显示消息"error:cannot open source file hunspel.hxx",但在聚焦后,错误消失。
谢谢你的帮助。
除非您要实际使用代码项目作者的自定义控件,否则不需要预处理器定义HSPELLEDIT_DLL。如果要定义它(或其他预处理器定义),请参阅/D(预处理器定义。
您的路径字符串需要是双\\而不是单\\转义,并且您有一些编译问题:
#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,你需要告诉你的项目如何找到它。要做到这一点,请打开你的项目设置,并在"配置属性">"C++">"常规"下的"其他包含目录"中打开Hunspell.hxx的路径。请参阅/I(附加包含目录)。
基于您的目录结构:
你的
Project > Properties > Configuration Properties > C++ > General > 'Additional Include Directories'
应该看起来像:.HunSpell-Srchunspell;%(AdditionalIncludeDirectories)
你的
Project > Properties > Configuration Properties > Linker > General > 'Additional Library Directories'
应该看起来像:.Debug_dlllibhunspell;%(AdditionalLibraryDirectories)
您还需要将myprojectmyprojectDebug_dlllibhunspelllibhunspell.dll
复制到您的项目输出目录(.\Debug),否则您的exe将找不到它。
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual C++ constexpr Hints
- 为什么它不适用于Visual 2019的原因
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- visual在c++中将十进制数转换为二进制数
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual C++(VS2017)中用户定义的转换不明确
- Visual C++GC接口如何启用它以及要包含哪个库
- visual是否可以在c++中创建一个接收无限数量相同类型(或至少相当数量)参数的函数
- visual c++,如何获取解决方案目录中的代码
- Visual Studio mkl_link_tool.exe链接错误
- C++-在Visual Studio 2010中使用HunSpell 1.3.2