C++ - Using HunSpell 1.3.2 with Visual Studio 2010 - c++

My goal is to create a simple Win32 Console application that uses HunSpell to spell-check a word the user has entered.
I tried to follow this codeproject tutorial which is for Visual Studio 2008 and HunSpell 1.2.1.
I don’t want to use the provided code, since I intend to write my own.
Furthermore I want to add HunSpell as a dll, not as a static library.
Following are the steps I took:
Created a Win32 console (empty) project with the name myproject.
Downloaded HunSpell 1.3.2 from SourceForge.org.
Copied hunspell-1.3.2\src\hunspell and win_api to myproject\myproject\HunSpell-Src
Added and converted project libhunspell myproject\myproject\HunSpell-Src\win-api\libhunspell.vcproj
to the solution.
Made my debug build use debug_dll and my release build release_dll of libhunspell in the Configuration Manager.
Rebuilt the libhunspell project, libhunspell.dll is generated in debug_dll and release_dll folders respectively.
Made my console project depend on libhunspell. (Added reference to libhunspell)
Copied dictionary files en_US.aff & en_US.dic to myproject\myproject\HunSpell-Dic after downloading them from SourceForge.org.
I can’t figure out how/where to add the processor define HSPELLEDIT_DLL that is mentioned in the codeproject tutorial.
Following the steps listed under “To use the functionality from the class library in the console application” on MSDN didn’t changed the result.
I want to test it with a program like this:
#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 produces the following error message if I try to compile it:
myproject\myproject\hunspell-src\win_api\hunspelldll.h(34): fatal error C1083: Cannot open include file: 'hunspell.hxx': No such file or directory
Hunspell.hxx is present in myproject\myproject\HunSpell-Src\hunspell. IntelliSense marks the #include "hunspell.hxx" as an error while the tab hasn’t focus with the message “Error: cannot open source file hunspell.hxx”, but after giving focus to it the error disappears.
Thank you for your help.

The preprocessor definition, HSPELLEDIT_DLL, is not needed unless you are going to actually use the codeproject author's custom control. In the case you want to define it (or other preprocessor definitions) refer to /D (Preprocessor Definitions).
Your path strings need to be double \\ instead of single \ escaped and you have some compile issues:
#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
}
For Hunspell.hxx, you need to tell your project how to find it. To do this, open your project settings and and the path to Hunspell.hxx to 'Additional Include Directories' under Configuration Properties > C++ > General. Refer to /I (Additional Include Directories).
Based on your directory structure:
Your Project > Properties > Configuration Properties > C++ > General > 'Additional Include Directories' should look like: .\HunSpell-Src\hunspell;%(AdditionalIncludeDirectories)
Your Project > Properties > Configuration Properties > Linker > General > 'Additional Library Directories' should look like: .\Debug_dll\libhunspell;%(AdditionalLibraryDirectories)
You will also need to copy myproject\myproject\Debug_dll\libhunspell\libhunspell.dll to your projects output directory (.\Debug) or your exe will not be able to find it.

Related

Struggling with libssh on Windows

The problem
I'm trying to build a project in Visual Studio 2015 on Win10 that makes use of libssh, but I'm having no luck getting it to work. I feel like I'm losing my mind here. I'm either completely blanking out or missing something incredibly obvious.
I've tried using the installer libssh-0.7.2-msvc.exe from the files section at https://red.libssh.org/projects/libssh/files. I then linked it to a test C++ project in VS2015. Using the sample code I'm able to compile it:
#include <iostream>
#define LIBSSH_STATIC
#include <libssh/libssh.h>
int main() {
std::cout << "Starting libssh test" << std::endl;
ssh_session my_ssh_session = ssh_new();
if (my_ssh_session == NULL) {
std::cout << "Failed to initialize" << std::endl;
}
ssh_free(my_ssh_session);
return 0;
}
(Note: I've tried both #define LIBSSH_STATIC and #define LIBSSH_STATIC 1 based on posts I've seen from my initial search for answers. I've even tried adding it to the preprocessor definitions in project properties.)
I can only compile it if my project is set to 32-bit, but I can't run the resulting executable. Doing so results in an error: "The code execution cannot proceed because ssh.dll was not found. Reinstalling the program may fix this problem." I'm statically linking ssh.lib, though, so I'm not sure why I'm even getting that error.
So I tried compiling libssh myself as 64-bit. It took some more tinkering than I expected (I had some issues with zlib, which eventually I just omitted since it's optional). I can compile my project as a 64-bit executable successfully, but once again, I can't actually run it. I get the same error about ssh.dll being missing.
For the sake of trying it, I removed the LIBSSH_STATIC define and tried to link just to the DLL. Copying the ssh.dll from the libssh distribution into my program folder and trying to run it, I get the error: "The application was unable to start correctly (0xc000007b). Click OK to close the application."
I'm not sure what I'm missing here, but I'm sure it's dumb and I'm overthinking it.
Project settings (all configurations, all platforms)
libssh is installed to G:\Libraries\libssh_0.7.2 on my machine.
Configuration Properties > VC++ Directories > Include Directories
G:\Libraries\libssh_0.7.2\include;$(IncludePath)
Configuration Properties > VC++ Directories > Library Directories
G:\Libraries\libssh_0.7.2\lib;$(LibraryPath)
Configuration Properties > Linker > Input > Additional Dependencies
ssh.lib;%(AdditionalDependencies)
libssh path summary
libssh_0.7.2
bin
ssh.dll
include
libssh
callbacks.h
legacy.h
libssh.h
libsshpp.hpp
server.h
sftp.h
ssh2.h
lib
ssh.lib
Install vkpkg
⊞ Win+X and open the powershell
Input vckpg install libssh:x64-windows
Integrate into Visual Studio: vcpkg integrate install
Then you can include <libssh.h> in Visual Studio.

Linker error LNK2019 when using DCMTK with Visual Studio

This is not a new question but the solutions haven't worked for me. I want to read dicom files using C++. I have 32-bit Windows PC with VS 2013 community edition.
This post and other answers therein suggested using DCMTK. I installed DCMTK (using CMake followed by VS) and configured it for use with VS using guidelines and links provided in this post. Then I wrote a simple test program and tried to compile it:
#include "stdafx.h"
#include "dcmtk\dcmdata\dctk.h"
#include "dcmtk\config\osconfig.h"
#include "dcmtk\dcmimgle\dcmimage.h"
#include <iostream>
using namespace std;
int main()
{
DicomImage *image = new DicomImage("test.dcm");
if (image != NULL)
{
if (image->getStatus() == EIS_Normal)
{
if (image->isMonochrome())
{
image->setMinMaxWindow();
Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits */));
if (pixelData != NULL)
{
/* do something useful with the pixel data */
}
}
}
else
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
}
delete image;
return 0;
}
Upon compilation, it gives the following error:
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _Netbios#4 referenced in function "unsigned char * __cdecl getMACAddress(unsigned char * const)" (?getMACAddress##YAPAEQAE#Z)
This error seems to be common but none of the following solutions work for me:
FAQ#27 and another post of DCMTK forum: It suggests using particular order of lib files to be included. My order of including files is as follows (I tried the reverse order as well but it didn't work):
All of this doesn't work. In fact, I'm not sure which lib files are supposed to be included? How to decide that?
I've also included "C:\Program Files\DCMTK\lib" under additional library directories and "C:\Program Files\DCMTK\include" under additional include directories in project properties.
Another similar question at stackoverflow has not been answered. Comments suggest to re-run CMake by disabling DCMTK_OVERWRITE_WIN32_COMPILER_FLAGS. I didn't do it because the DCMTK help page says don't disable this unless you really know what you're doing.
Can someone please guide?
The NetBios function resides in NETAPI32.LIB, so you can try moving NetAPI32.lib (which is in your list) to the top of that list.
Not sure which version of the DCMTK you use, but for the current development snapshot you need the following standard libraries (on Windows): "ws2_32 netapi32 wsock32". This information can be found in DCMTK's CMake files. By the way, you don't seem to use CMake for your project, right?
I think you misspelled dcmsign.lib as dcmsig.lib.
If changing that doesn't fix it, I would suggest the following order based on the support page that you linked to:
NetAPI32.lib
WSock32.lib
ofstd.lib
oflog.lib
dcmdata.lib
dcmsign.lib
dcmnet.lib
dcmsr.lib
dcmqrdb.lib
dcmtls.lib
dcmwlm.lib
dcmimgle.lib
dcmpstat.lib
dcmjpls.lib
dcmjpeg.lib
dcmimage.lib
ijg16.lib
ijg12.lib
ijg8.lib
I think that in this list, each library has to come after all the libraries that it depends on.
check your .lib and vs platform if the same ,such lib for x64, then your vs platform must be x64.
I had the same error. You can go to project properties-> linker -> input -> Additional Dependencies-> Edit -> add these two libraries-( netapi32.lib,wsock32.lib) before all other libraries . This solved the error for me .

Code coverage error (No binaries were instrumented)

Problem:
Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
I'm attempting to use the code coverage function but it returns this error:
Empty results generated: No binaries were instrumented. Make sure the
tests ran, required binaries were loaded, had matching symbol files,
and were not excluded through custom settings. For more information
see http://go.microsoft.com/fwlink/?LinkID=253731
My .coverage file is full of non-sense, starting with "PCHÿ". I thought my problem looked similar to this one: Issue with Code Coverage in VS 2012, but deleting the .suo file and running Visual Studio in admnistrator didn't solve anything.
How to replicate:
1) Create new empty project "MyProject"
2) Add new file "Calculator.hpp"
#pragma once
class Calculator
{
public:
int add(int a, int b);
int sub(int a, int b);
};
3) Add new file "Calculator.cpp"
#include "Calculator.hpp"
int Calculator::add(int a, int b)
{
return a + b;
}
int Calculator::sub(int a, int b)
{
return a - b;
}
4) Add new file main.cpp
#include "Calculator.hpp"
#include <iostream>
using std::cout;
int main()
{
Calculator calc;
std::cout << calc.add(5, 11) << std::endl;
std::cout << calc.add(11, 1) << std::endl;
return 1;
}
5) Build solution. (0 errors)
6) Add new test project to solution as explained here: https://msdn.microsoft.com/en-us/library/hh419385.aspx#objectRef:
Add new Native Unit Test Project to solution "CalculatorUnitTest"
Add "main.obj" and "Calculator.obj" to Linker/Input/Additional Dependencies of "CalculatorUnitTest"
Add path to obj files to Linker/General/Additional Library Directories of "CalculatorUnitTest". (In my case: D:\JF\Programming\Tests\MyProject\MyProject\Debug)
Add the header directory of "MyProject" to VC++ Directories/Include Directories. (In my case: D:\JF\Programming\Tests\MyProject\MyProject).
7) Replace code in "unittest1.cpp" with:
#include "stdafx.h"
#include "CppUnitTest.h"
#include <Calculator.hpp>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace CalculatorUnitTest
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
Calculator calc;
Assert::AreEqual(5, calc.add(2, 3));
}
};
}
8) Build solution (0 errors, TestMethod1 appear in Test Explorer)
9) Right-click TestMethod1, "Run Selected Tests" (Test successfully passes)
10) Right-click TestMethod1, "Analyze Code Coverage for Selected Tests" (Code coverage fails).
At D:\JF\Programming\Tests\MyProject\Debug, I have both my MyProject.exe and MyProject.pdb with the CalculatorUnitTest.dll.
First of all, I am not sure if Visual Studio 2015 (C++) supports ".exe" type project for the unit test. But you are using ".obj" directly from your project. You need to place ".pdb" file in the same folder.
I created a static library project and added the unit test. Same problem on my environment.
Future here. Same problem, except my test target is a Static Library project in the same Solution.
MyLib - Code that will be tested.
MyLibTests - Project containing the tests.
Solution contains both projects.
MyLibTests has project Reference to MyLib.
<OutDir> (in .vcxproj) aka Output Directory aka $(OutDir) identical in both projects. (My value <OutDir>$(SolutionDir)$(Configuration)_$(Platform)\</OutDir>)
On your test project (MyLibTests), go
Properties
Select [Debug|platform]
Linker
Debugging
Generate Debug Info = Optimize for debugging /DEBUG
Mine was initially set for /DEBUG:FASTLINK.
Via this social MSDN post I figured it had something to do with the PDB, because MSDN (aka now "learn.microsoft.com") said this is an important step in several places, and I assume PDB are used trace calls, I assume using DbgHelp.dll.
And this sort of checklist modified from another social MSDN post:
Test project References properly set (MyLib.lib is in the same Solution as MyLibTests.dll)
Build order/dependency set/verified.
I also have Autorun on Build.
Rebuild (this should rebuild dependencies).
made sure all test were run(all test run successful)
not using optimisation (Profile Guided/Instrumentation etc).
<OutDir> aka Ouput directory should be the same, where both MyLibrary.lib/dll/exe ends up with their MyLibrary.pdb since PDB paths are linked in the exe/dll.
not using a runsettings file
Unload all other projects other than affected ones

vs2015 and vc++ external dependencies error on build

i am learning vc++ and i make my first application win32 console and just write simple code and i get 20 error from external files automatic included
i change compile as to c++ and not using precompiled headers but stil have errors
here is my code
#include <iostream>
int main()
{
//cout << "hello !" << endl;
return 0;
}
how can i fix it ?
Edit :
i have win7 and vs2015 perhaps helps
Edit 2:
last picture is for an empty project this one is for a win32 console app
I think you have created a project set to use precompiled header. Can you start with an empty project and add source file?
And don't forget to set "Not using precomplied header" in file option

eclipse c++ in ubuntu

I was trying to run following code in eclipse in ubuntu 12.04 but It keeps giving me error. could you please tell me why this is happening ? Thanks.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
Symbol 'std' could not be resolved
Symbol 'cout' could not be resolved
Symbol 'endl' could not be resolved
This is the C++ parser of Eclipse who can't find the symbols.
You could add the config to your already created project but it can be painful. So simply create a new C++ project :
File > New > C++ Project
Then :
Pick the type of project you want, like "Executable > Empty Project" (or maybe "Makefile Project > Empty Project") and make sure to select Linux GCC in the Toolchains. This will add all the default includes in the configuration so that the C++ parser finds everything. Click Finish, paste your code in a C++ file and enjoy.
For information, you can see these include paths in the Project Properties > C/C++ General > Paths and Symbols > Includes > GNU C++.