0

I am attempting to use Hunspell DLL in C++ Builder but have nothing but troubles.

So I try to resort to compiling as static library. But even that doesn't go smooth. The steps I did so far:

  1. downloaded the latest Hunspell from https://github.com/hunspell/hunspell/releases

  2. unzipped and created in C++ Builder - New / Other / Static Library

  3. right clicked and added all *.cxx files from src/hunspell folder

  4. Clicked 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).

Any help in building static hunspell lib (or even DLL) from C++ Builder appreciated.

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.

Coder12345
  • 3,431
  • 3
  • 33
  • 73
  • 1
    Most 3rd party libraries are NOT compatible with C++Builder out of the box (mainly because Borland compilers have gotten a bad reputation for being too old and not worth supporting, until recent years as Embarcadero has released new C++11 and soon C++17 compilers). Such libraries usually require some amount of tweaking first. What are the actual troubles you are having with using the DLL? You are probably just not using it correctly, which would more likely be easier to fix than trying to recompiling the entire library. Also, which version of C++Builder are you using? – Remy Lebeau Aug 29 '18 at 23:20
  • 1
    As Remy said, if you already have a DLL, it should be quite easy to *use* the DLL, instead of recompiling things. So rather tell us what problems you have with the DLL. – Rudy Velthuis Aug 30 '18 at 18:05
  • Thank you for helping - as you've said, it turned out to be easier to use DLL, once I figured out how to remove the dependencies from the DLL. I'll write an answer to describe this. I've created a new question though - https://stackoverflow.com/questions/52121623/dynamically-linked-dll-is-loaded-immediately-after-starting-the-application – Coder12345 Aug 31 '18 at 19:32

1 Answers1

0

As Remy Lebeau and Rudy Velthuis pointed out it turned out to be easier to use DLL instead. 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. 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. So I used the current master version (https://github.com/hunspell/hunspell).

2) used Visual Studio 2015 Community to build the DLL - libhunspell.dll. To avoid dependencies, I used the /MT option in the compiler. 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. Even though the compiler reported some warnings which is probably another question, it did manage to build the DLL.

3) created import library using 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). Another option is to add the lib to the project instead of the #pragma statement.

Coder12345
  • 3,431
  • 3
  • 33
  • 73