Compiling Hunspell as static library in C++ Builder - c++

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:
downloaded the latest Hunspell from https://github.com/hunspell/hunspell/releases
unzipped and created in C++ Builder - New / Other / Static Library
right clicked and added all *.cxx files from src/hunspell folder
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.

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.

Related

Understanding how to compile C++ project

I'm new to coding and Visual Studio. I know and understand how to create, save and compile a new C++ project in Visual Studio. I understand that a new VS project creates a solution file in the directory which then I can use to open the project, etc.
What I don't understand is how to compile a C++ project which doesn't have a VS solution file. I mean, do I have to manually create a project and import files and then build it?
Please take this GitHub project as an example. Under information, it clearly states the following:
Building
To build a static library (./lib/ompeval.a) on Unix systems, use make.
To enable -msse4.1 switch, use make SSE4=1. Run tests with ./test. For
Windows there's currently no build files, so you will have to compile
everything manually. The code has been tested with MSVC2013, TDM-GCC
5.1.0 and MinGW64 6.1, Clang 3.8.1 on Cygwin, and g++ 4.8 on Debian.
Now, what I don't understand is how do I build this project in my VS software so that I can successfully run it? Any help would be appreciated. Thank you.
As you said it, create a new project in Visual Studio and just import the source and header files. Looking at the makefile, there doesn't seem to be any pre or post build events so you can import the files and compile them right away (as long as the code is platform compatible ofc).
You may have to create multiple projects. One for the static library and one for the test files, since Visual Studio projects usually have one output type only. Mostly one of the presets: dynamic library (dll), static library (lib) or executable (exe).

Change VS C++ compilar to vc 11 to vc12

I complied boost library by using vc 12 but my visual studio has vc 11. when I try to run boost sample program which is used boost (c++ library ) visual studio 2013 shows cannot open file 'libboost_regex-vc110-mt-gd-1_54.lib my libray path -(..\boost_1_54_0 2\stage\lib) im having libboost_regex-vc120-mt-gd-1_54 . think that issue I can solve by changing visual studio complier vc11 to vc12. how do I do that please help me.
Unless there is compiler or OS related dependency, you can solve it by linking with appropriate library. Check the setting of your project. Where, it was expecting vc110 library, change it to corresponding vc120 library.
If it does not work (because of some other issues like compiler specific problem, platform specific problem, or duplicate symbols as it was linked with different C runtime library), you can try the following:
Rebuild boost but with dynamic CRT library (instead of static library) (check /MD or /MT option). In this way, you need not to change either of compiler.
If nothing works, build both application and library using same compiler.

Using fuzzylite in Visual Studio 2010

Has anyone done this before ? I am not able to get it to work.
Following are my steps:
Download the windows package from link
I can run qfuzzylite (gui-tool) without any problem. Now I want to use the fuzzylite lib in my Visual Studio + Qt Integration Project.
In the CMake GUI I give fuzzylite source folder as the input folder and select Visual Studio 2010 as the compiler.
I am able to generate the Visual Studio fuzzylite solution in CMake without any errors.
Then, I tried to build the Visual Studio solution, but it fails with some weird errors. However, it does generate the fuzzylite-dbg.lib file (which I need).
Then I use this lib file and the fuzzylite.dll and include the path to the Headers in the VS Project. The project builds without any errors.
Now in the code I am doing
fl::Engine* engine = new fl::Engine("simple-dimmer");
This fails with the following exception:
exception text: bad allocation
exception type: class std::bad_alloc
Thank you for your detailed steps, but the solution seems to be a bit random (or weird as you put it). Unless more information is provided about the error, I strongly discourage the use of such a solution to attempt any fix to fuzzylite.
If you are running into problems, I strongly encourage you to report the problem in the forums at http://www.fuzzylite.com, where I and others will be very happy to help you.
As for the compiling errors, fuzzylite treats warnings as errors. A warning that is being raised in fuzzylite 4.0 when compiled using Visual Studio (not from console via nmake), and potentially in previous versions, is warning C4702, which refers to unreachable code. You can fix this by adding in file fl/fuzzylite.h the following line within the #ifdef FL_WINDOWS (together other #pragmas):
#pragma warning(disable:4702) //Ignore unreachable code
If the library was not built correctly, errors are bound to happen during runtime.
Ok, got it :)
Here are the steps for future reference:
Download the windows package from link
In the CMake GUI I give fuzzylite source folder as the input folder and select Visual Studio 2010 as the compiler. Now, if you want to use the lib in Debug mode tick the FL_DEBUG box (this is where I went wrong)
Now on clicking "generate", it will generate 5 projects:
ALL_BUILD
fl-bin
fl-shared
fl-static
INSTALL
ZERO_CHECK
Now in the Project properties in fl-bin, shared and static go to the Project Properties. In C/C++ go to Preprocessor get rid of the space in FL_DATA="mm.dd.yyyy " to "mm.dd.yyyy" (weird).
The solution should build fine and will generate fuzzylite-dbg.dll and fuzzylite-dbg.lib in the lib folder.
Use these files in your VC Project by adding the fuzzy-dbg.lib as the linker input and place the dll in the solution folder. Give the path "path\to\fuzzylite\fuzzylite." to the Include Directories.
Do the same process for Release mode (don't tick the FL_DEBUG flag)

How do I install Crypto++ in Visual Studio 2010?

I downloaded http://www.cryptopp.com/#download 5.6.1 and have no clue that to do at this point. I am a total noob and need good instructions. thanks.
Directly from the readme (Which can be found here Crypto++ Svn Trunk):
* MSVC-Specific Information *
On Windows, Crypto++ can be compiled into 3 forms: a static library including all algorithms, a DLL with only FIPS Approved algorithms, and a static library with only algorithms not in the DLL. (FIPS Approved means Approved according to the FIPS 140-2 standard.) The DLL may be used by itself, or it may be used together with the second form of the static library. MSVC project files are included to build all three forms, and sample applications using each of the three forms are also included.
To compile Crypto++ with MSVC, open the "cryptest.dsw" (for MSVC 6 and MSVC .NET 2003) or "cryptest.sln" (for MSVC 2005 - 2010) workspace file and build one or more of the following projects:
cryptopp - This builds the DLL. Please note that if you wish to use Crypto++ as a FIPS validated module, you must use a pre-built DLL that has undergone the FIPS validation process instead of building your own.
dlltest - This builds a sample application that only uses the DLL.
cryptest Non-DLL-Import Configuration - This builds the full static library along with a full test driver.
cryptest DLL-Import Configuration - This builds a static library containing only algorithms not in the DLL, along with a full test driver that uses both the DLL and the static library.
To use the Crypto++ DLL in your application, #include "dll.h" before including any other Crypto++ header files, and place the DLL in the same directory as your .exe file. dll.h includes the line #pragma comment(lib, "cryptopp") so you don't have to explicitly list the import library in your project settings.
To use a static library form of Crypto++, make the "cryptlib" project a dependency of your application project, or specify it as an additional library to link with in your project settings. In either case you should check the compiler options to make sure that the library and your application are using the same C++
run-time libraries and calling conventions.
If you have any questions feel free to ask and i'll update the anwser with my responses.
I downloaded http://www.cryptopp.com/#download 5.6.1 and have no clue what to do at this point...
This is a very late answer, but the project has released some new files to help folks use Visual Studio 2010 and above.
The project had to release the updated files because VCUpgrade (provided with Visual Studio 2010) does a fairly poor job with this particular project. It has been a source of problems for a few years, and even visually impaired users were commenting about it. The problems were not fixed in VS2012, VS2013 and VS2015, so we don't believe Microsoft has any intentions of fixing the problems.
To use the updated files, download the latest Crypto++ release from the website. Then, visit the Crypto++ wiki and fetch vs2010.zip from the page Visual Studio. Unzip vs2010.zip over the Crypto++ files. Finally double-click the file called cryptest.sln to have Visual Studio open the solution file.
The Crypto++ wiki page also offers project files that provide dynamic runtime linking for both VS2005 and VS2010.
If you convert cryptest.sln from VS2005 to VS2010, you will meet a problem. When you compile source code, the compiler will show an error:
c1xx : fatal error C1027: Inconsistent values for /Ym between creation and use of precompiled header
You can resolve this problem by:
Going to Project Properties --> Configuration Properties --> C/C++ --> Precompiled Headers
Changing it to "Not Using Precompiled Headers"
You'll need to compile the library before using it with anything. You can't just install it. Here is a page from their wiki about compiling the library: http://www.cryptopp.com/wiki/Compiling

Using a DLL with unmanaged code in Visual Studio 2010?

I'm fairly new to C++ and an trying to figure out to use the TagLib library for a project I am working on. I'm working with unmanaged C++ in Visual Studio 2010 on Windows 7 64bit. I've never used an external library before so I'm very confused on how to go about this.
From this blog entry I got the libtaglib.a and taglib.dll files. I ran across this SO question on how to use TagLib, but it deals with QT Creator, not Visual Studio and I'm not knowledgeable enough about the subject to understand what is being said to translate it into what needs done for Visual Studio.
So, some questions:
Is it even possible to do this with unmanaged code?
What exactly is the function of a .a file?
Most importantly, how do I go about using the taglib.dll in my program??
I've been all over Google looking for a way to do this, but my major problem is that everything I run across is over my head. Please let me know if more info is required. Any help is very much appreciated! Thanks!
I seem to have gotten it working successfully. Here's a rough outline of what I did:
1.) I used CMake to generate the Visual Studio solution.
2.) I attempted to build the tag project in the VS solution, but it failed.
3.) I made the corrections to a few source files as outlined here: http://old.nabble.com/taglib-fails-to-compile-with-MS-VC%2B%2B-2010-td29185593.html
4.) I built the tag project again in release mode. This time it was successful.
5.) I copied the resulting dll, def, and lib files to the same directory as the source files for my project.
6.) I copied the header files from the taglib source to a subdirectory in my project (not sure if this entirely good practice)
7.) In my project settings, I set the subdirectory with the header files as an additional include directory.
8.) I added the dll, exp, and lib files to my project by just going to Add>Existing Item.
9.) I added some code from the taglib examples and built it. Everything worked so I think I got it.
One caveat I ran into, since the DLL was built in release mode, my project had to be run in release mode or it would crash. I'm guessing that if I replaced the DLL with one built in debug mode I could run my program in debug mode, but I have not tried this.
You cannot use libraries specific to GCC (you can tell because they have .a extensions) with Visual Studio. You will have to build the library from source in order to use it with MSVC. Once you have done that it's a simple matter of adding the .lib generated from the build process to your project and things should work out of the box. (Note that it's a .lib you need whether you're compiling for dynamic linking or not -- doesn't matter in msvc land)
EDIT -- after looking at TagLib itself --
In order to compile TagLib you'll need to get the CMake build system, and TagLib itself, and have CMake build you a visual studio solution. Using that solution you'll be able to build the .libs and .dlls you need. Note that because TagLib is a KDE library, you'll probably need to also build some QT bits in order for everything work work successfully. However, I don't have specific experience with the library so I'm not going to be all that helpful here.
Yo do not have to recompile the source (to create the .lib file) if you have the .dll file. With dumpbin /exports and lib (both came with Visual Studio) yo can create a lib that you can link with your application. In this link you can see a nice explanation: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/
But as Billy Said, probably you would need other parts of QT to use this library.