[英]Compiling Hunspell as static library in C++ Builder
I am attempting to use Hunspell DLL in C++ Builder but have nothing but troubles. 我正在尝试在C ++ Builder中使用Hunspell DLL,但是除了麻烦之外什么都没有。
So I try to resort to compiling as static library. 因此,我尝试诉诸于编译为静态库。 But even that doesn't go smooth.
但是,即使那样也不顺利。 The steps I did so far:
我到目前为止所做的步骤:
downloaded the latest Hunspell from https://github.com/hunspell/hunspell/releases 从https://github.com/hunspell/hunspell/releases下载了最新的Hunspell
unzipped and created in C++ Builder - New / Other / Static Library 在C ++ Builder中解压缩并创建-新建/其他/ 静态库
right clicked and added all *.cxx files from src/hunspell
folder 右键单击并添加
src/hunspell
文件夹中的所有* .cxx文件
Clicked Build
点击
Build
The error which comes up is: 出现的错误是:
[BCC32 Error] cwchar(33): E2141 Declaration syntax error
cwchar is a file which is part of C++ Builder and not Hunspell as it seems (which only includes it). cwchar是C ++ Builder的一部分,而不是Hunspell(仅包含它)。
Any help in building static hunspell lib (or even DLL) from C++ Builder appreciated. 从C ++ Builder构建静态hunspell lib(甚至DLL)的任何帮助都值得赞赏。
Thanks in advance! 提前致谢!
Edit: I was able to progress further by using more recent C++ Builder Berlin (the above error was in 2010 version) but it still reported linker errors, so I ended up using the DLL - see the answer. 编辑:我可以通过使用最新的C ++ Builder Berlin(上面的错误是2010年版本)进一步进步,但是它仍然报告链接器错误,所以我最终使用了DLL-请参见答案。
As Remy Lebeau and Rudy Velthuis pointed out it turned out to be easier to use DLL instead. 正如Remy Lebeau和Rudy Velthuis指出的那样,事实证明,使用DLL更加容易。 I've also discovered a few more tricks along the way which I will describe below.
我还发现了一些下面将介绍的技巧。
1) when trying to create static lib file using C++ Builder (Berlin), it turned out that the current hunspell-1.6.2.zip is not compiling without errors. 1)尝试使用C ++ Builder(柏林)创建静态lib文件时,事实证明当前的hunspell-1.6.2.zip并未正确编译。 However, the hunspell-master.zip which is a clone of the SVN master, it at least compiled, although there were some linker errors - but I figured that master version is better to use as a base for building the DLL.
但是, hunspell-master.zip是SVN master的一个克隆,至少已编译,尽管存在一些链接器错误-但我认为master版本最好用作构建DLL的基础。 So I used the current master version ( https://github.com/hunspell/hunspell ).
因此,我使用了当前的主版本( https://github.com/hunspell/hunspell )。
2) used Visual Studio 2015 Community to build the DLL - libhunspell.dll . 2)使用Visual Studio 2015社区构建DLL- libhunspell.dll 。 To avoid dependencies, I used the
/MT
option in the compiler. 为了避免依赖性,我在编译器中使用了
/MT
选项。 I had many problems using the version of the DLL which was dependent on VC++ 2015 Redistributable ("Access Violation" errors immediately after calling some DLL functions), so statically linking the Redistributable to remove the dependency, all of these problems magically disappeared. 我在使用依赖于VC ++ 2015 Redistributable的DLL版本时遇到了许多问题(调用某些DLL函数后立即出现“访问冲突”错误),因此静态链接Redistributable以删除依赖项,所有这些问题都神奇地消失了。 Even though the compiler reported some warnings which is probably another question, it did manage to build the DLL.
即使编译器报告了一些警告,这可能是另一个问题,但它确实设法构建了DLL。
3) created import library using implib -a -c -f libhunspell.lib libhunspell.dll
3)使用
implib -a -c -f libhunspell.lib libhunspell.dll
创建导入库
4) finally, linked to the .cpp file using #pragma comment(lib, "libhunspell.lib")
(for older RAD Studio versions) or #pragma comment(lib, "libhunspell")
for newer RAD Studio versions which support 64bit compiler). 4)最后,使用
#pragma comment(lib, "libhunspell.lib")
(对于较旧的RAD Studio版本)或#pragma comment(lib, "libhunspell")
,链接至.cpp文件,以获取支持64位编译器的较新的RAD Studio版本。 )。 Another option is to add the lib to the project instead of the #pragma
statement. 另一种选择是将库而不是
#pragma
语句添加到项目中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.