C++ - Using Hunspell with MFC - c++

After I managed to get Hunspell working with a Win32 console application, I want to use Hunspell in an MFC application in the same solution.
I get the following error when I try to compile the MFC application.
spellcheck\hunspell-src\hunspell\replist.hxx(23): error C2062: type 'const char' unexpected
spellcheck\hunspell-src\hunspell\replist.hxx(23): error C2238: unexpected token(s) preceding ';'
Some information about the solution:
The solution is called spellcheck.
The Hunspell source files are located in spellcheck\hunspell-src\hunspell and spellcheck\hunspell-src\win_api.
The project libhunspell has been imported and compiles without errors.
A console application in the solution uses the same hunspell dll/source files and has no errors.
The console application has been setup accordingly to this thread
The folders HunSpell-Src and HunSpell-Dic are NOT located in a project folder but in the solution folder spellcheck and referenced properly.
I have setup the MFC application as following:
Added a new MFC application (SDI) as project to the solution called MFC2.
Added a reference to the project libhunspell to MFC2.
Project > Properties > Configuration Properties > C++ > General > Additional Include Directories has been set to: ..\hunspell-src\hunspell;%(AdditionalIncludeDirectories) (the same as the console application)
Project > Properties > Configuration Properties > Linker > General > Additional Library Directories has been set to: ..\hunspell-src\win_api\Debug_dll\libhunspell;%(AdditionalLibraryDirectories) (the same as the console application)
Added #include "../HunSpell-Src/win_api/hunspelldll.h"under #include MainFrm.h in Mainfrm.cpp.
I decided to put the #include of hunspelldd.h in Mainfrm.cpp and omit setting up a dialog and calling it in order to keep this question as short as possible. Nevertheless I have setup a project as described that produces said error messages.
Because the console application compiles fine, I assume something MFC specific is causing the problem.
Thank you for your help.

Add "#undef near" before class declaration in replist.hxx

I'd look for an error in the include file just before replist.hxx, perhaps a missing ending semicolon on a class definition.

Related

VS2019:fatal error C1083 Cannot open header file: 'opencv.hpp'

It is all fine when I was writing the code, that is, when I included the header file "opencv2/opencv.hpp",and VS2019 can indeed "see" it,in other words, I can use the class that is in the opencv.hpp, but only when I complied the project,c1083 occurred
before i added the function DrawLine(),i compiled for times,with no err.and then i added the function DrawLine(..),error occurred
this is the total source code
a.ha.cpp
//a.h
#include<opencv2\opencv.hpp>
using namespace cv;
class Canvas{
Mat mat_canvas;
void Init(){
mat_canvas.create(1024,1024,CV_32FC3);
}
void DrawLine(float ax,float ay,float bx,float by);
}
//a.cpp
#include"a.h"
void Canvas::DrawLine(float ax,float ay,float bx,float by){
cv::line(this->mat_canvas,Point2f(ax,ax),Point2f(bx,by),Scalar(1,1,1));
}
error msg was:
fatal error C1083 Cannot open header file: 'opencv.hpp': no such file or dir
i know i can create a new solution and move my old solution to it,but it takes time,and i can't actually know whether this issue will happen again in my new solution
Any answer will be helpful
Actually there are most of the time possibility of missing "Additional include directory path" or wrongly setup.
Where to find in Visual Studio:
To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Set
C++ compiler and build properties in Visual Studio.
Select the Configuration Properties > C/C++ > General property page.
Modify the Additional Include Directories property.
Visual Studio 2019 C++ Project configuration
Example project setup is described in below link:
Example setup

Visual C++ : XGBoost does not work when called from a DLL

I have a requirement to use XGBoost within a Visual C++ project DLL.
I have been able to download and build the XGBoost source using VC++ and CMake.
When I include the XGBoost code in a test console application, it works fine.
However, when I try to replicate what I've done with the console application in a DLL project, it won't compile.
I am struggling to even use a basic XGBoost type within the project.
I suspect the problem is my ignorance with DLL projects and would appreciate your help.
Here's what's happening in my DLL project:
When I use the following include as the very first line in a cpp class file, it compiles:
#include <xgboost\c_api.h>
With it compiling, if I try to use a simple type defined in this include file, the build fails with the following message:
...\dll_test\xgb_driver.cpp(20): error C2065: 'BoosterHandle': undeclared identifier
This is the line that causes the error:
BoosterHandle my_handle;
"BoosterHandle" is in fact defined in <xgboost\c_api.h>
When I put the include below any other include, I get the following error messages:
1>c:\tools\src\xgboost\include\xgboost\c_api.h(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\tools\src\xgboost\include\xgboost\c_api.h(29): error C2146: syntax error: missing ';' before identifier 'bst_ulong'
Below is a little more information on what I did to get XGBoost working with a console app and how I created the DLL project.
=-=-=-=-=-=
Here's what I did to use XGBoost with a console. Everything about it seems to work. I've tested the model predictions, and they are
consistent with what I'm seeing in R.
Using the documentation found here:
https://xgboost.readthedocs.io/en/latest/build.html
I downloaded the XGBoost source and built it using CMake and Visual Studio 2015.
Under Project > Linker > Input > Additional Dependencies,
I added the xgboost.lib file
Under Project > Linker > General > Additional Library Directories
I added a reference to ...\xgboost\build\Release
Under Project > VC++ Directories > Include Directories
I added the path to ...\xgboost\rabit\include and ...\xgboost\include
I put the xgboost.dll in the directory where the .exe is generated.
From here, it was smooth sailing.
=-=-=-=-=-=
Here's what I've done to create a Visual C++ DLL Project:
After choosing File > New > Project, I select an ATL DLL Project (this is part of the project requirement).
For the XGBoost include to the project, I repeated steps 1-5 above, but placed the xgboost.dll file where the
project DLL would be generated.
Here is the source for the header file for the simple class I have created:
#pragma once
class XGB_Driver
{
public:
XGB_Driver();
~XGB_Driver();
float callXGB(float sample_input);
};
Here is the source for the simple cpp file:
#include <xgboost/c_api.h>
#include "stdafx.h"
#include "XGB_Driver.h"
XGB_Driver::XGB_Driver()
{
}
XGB_Driver::~XGB_Driver()
{
}
float XGB_Driver::callXGB(float simple_input) {
BoosterHandle my_handle;
return(0);
}
Why this doesn't work for the ATL DLL project, but does for the console app really has me banging my head against the keyboard.
Your help would be very much appreciated.
Best,
Dave
With the help of CristiFati, I believe this question has been answered.
For whatever reason, it seems that using XGBoost with C++ in a DLL project requires additional includes above and beyond what is required for using it in a console application.
I am currently building the DLL project with the addition of:
#include <cstdint>

Link: fatal error LNK1561: entry point must be defined VS2015 developer cmd window

I have read a ton of this same question, but I appear to be doing everything correctly as all suggestions advise, but am still getting this error.
I have simple .cpp and .h files in C++ using Visual Studio 2015. My program runs perfect from the gui. I need to run it in the visual studio developer command window to get the results there, this is a verified console application. I have copied the files to their own directory using:
C:\RunDirectory>copy C:\SaveDirectory\
The system verifies that it copies all 15 files.
When I run this command:
C:\RunDirectory>cl Aprogram.cpp
Then I get the error.
I have a main that is returning an int, and this is a console application with the correct linker settings: Console (/SUBSYSTEM:CONSOLE)
Any ideas? I'm pretty stumped.
This is my driver file:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include "JollyBanker.h"
using namespace std;
int main()
{
JollyBanker theBanker;
theBanker.BuildQueue("BankTransIn.txt");
theBanker.ProcessQueue();
theBanker.DisplayResults();
return 0;
}
File Aprogram.cpp is a source code file, which is compiled and linked
into an executable by Visual Studio IDE. Assuming that default project
settings are used, this executable is located in "Debug" or "Release"
subdirectory of the directory that contains your solution and it is named
ProjectName.exe (where "ProjectName" is the name of the project
within the solution that contains Aprogram.cpp)
Also, you mentioned that you want to make sure it works outside VS. Note
that if you have used the default settings, you will have problems when you
run this executable on another machine. To solve this, I suggest that you
change the runtime library that you are linking to. To do this, right click on
the project in Solution Explorer and select "Properties". Go to "C/C++" -> "Code Generation"
and change the value of "Runtime Library" to "Multi-threaded Debug (/MTd)" for "Debug" configuration, or to "Multi-threaded (/MT)" for "Release" configuration.

Having trouble embedding Lua for Windows install into C++ program

This is the first question I have found myself not being able to get to the bottom of using my normal googling/stack overflowing/youtubing routine.
I am trying to compile a minimal Lua program inside of a C++ environment just to ensure my environment is ready to development. The Lua language will be later used for User Interface programming for my C++ game.
First some basic information on my environment:
Windows 7 64-bit
Visual studio 2010
Lua for Windows 5.1 (latest build I could download from google code)
Here is the code I am trying to compile:
// UserInt.cpp : Defines the entry point for the console application.
//
#pragma comment(lib,"lua5.1.dll")
#include "stdafx.h"
#ifndef __LUA_INC_H__
#define __LUA_INC_H__
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
int _tmain(int argc, _TCHAR* argv[])
{
lua_State * ls = luaL_newstate();
return 0;
}
#endif // __LUA_INC_H__
Here is the Error I am getting:
1>UserInt.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _wmain
1>c:\users\deank\documents\visual studio 2010\Projects\UserInt\Debug\UserInt.exe : fatal error LNK1120: 1 unresolved externals
Things I have tried:
I have read about lua_open()(and several other functions) no longer being used so I tried the newstate function instead. I get the same error. This was more of a sanity check than anything. I am using 5.1 and not 5.2 so I do not think this really matters.
I have also read this thread Cannot link a minimal Lua program but it does not seem to help me because I am not running the same environment as that OP. I am on a simple windows 7 and visual studio environment.
The top pragma comment line was something I saw in yet another thread. I get the same error with or without it.
I have gone into my visual studio C++ directories area and added the lua include to the includes and the lua lib to the libraries.
So it seems like my program is seeing the .h and seeing the symbol. But for some reason it is not getting the .cpp implementation for the functions. This is why I was hoping including that .dll directly would help fix the problem, but it hasn't.
So, I feel like I have exhausted all of my options solving this on my own. I hope someone is able to help me move forward here. Lua looks like an awesome language to script in and I would like to get my environment squared away for development.
I hope it is just some silly error on my part. I believe I have provided as much information as I can. If you need more specifics I will update with info if I can provide it.
Edit1
Tried the solution in this Can't build lua a project with lua in VS2010, library issue suspected
That did not work either.
You'll need to have the library (.LIB) file and add that to VS. Use Project > Properties and go to Linker > Input and add the full .lib filename to the "Additional Dependencies" line. Note that the .LIB is different from the .DLL.
Personally, I prefer adding the source code to my project, over referencing the dynamic link library. The following procedure will let you do as such.
Download the source code ( http://www.lua.org/ftp/ ), uncompress it.
In Visual Studio, choose File > New > Project and choose Visual C++, Win32, "Win32 Console Application".
In your project in Visual Studio, add all the source code, except luac.c. Also delete the main() function out of the file that VS created for you. This is usually given the name of the project you specified with the .cpp file extension. You could just remove this file all-together from the project.
Build and Run.
This is the Lua console

C++ - Using HunSpell 1.3.2 with Visual Studio 2010

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.