Include zxing in C++ project - c++

I try to integrate zxing in an other C++ project. I'm using Visual Studio 2012 with Windows 7.
I would like to run the sample code from the zxing repository:
zxing example
If i compile my project i get an error:
zxing_integration.obj : lnk2001 unresolved external symbol
zxing_integration.exe fatal error lnk1120 1 unresolved external symbol
what I've done so far:
create an win32 console application named zxing_integration in the folder ...\workspace
create an folder ...\workspace\git and clone the zxing repository
create an folder ...\workspace\zxing-cpp\build and build the zxing project with the command line prompt cmake ..\workspace\git\zxing-cpp -G "Visual Studio 11 2012" (i think this step is not necessary)
Added under project settings->C/C++ -> additional include directorys (all configurations) the following pathes: ...\workspace\git\zxing-cpp\core\src and ...workspace\git\zxing-cpp\cli\src
After these steps nothing is red underlined or marked in Visual Studio, so i think the source files can be found. If i build the project i get the two errors. i think that the linker needs .lib files, but i can not found zxing libs in the project. Do i have to build the lib files?
It is strange that the error appears in line 258 source = ImageReaderSource::create(filename); and not in line 256 Ref<LuminanceSource> source;. It seems that LuminanceSource can be found.
Ref<LuminanceSource> source;
try {
source = ImageReaderSource::create(filename);
} catch (const zxing::IllegalArgumentException &e) {
cerr << e.what() << " (ignoring)" << endl;
continue;
}

For anyone stumbling over this dated question: there is a 'new' c++ implementation with lots of improvements compared to the upstream Java project: ZXingCpp
It can be built on Windows/macOS/Linux/Android/WASM.

Related

unresolved external symbol error even when setup of visual studio project is done properly

In a nutshell
I am tring to use an existing C++ library.
The problem is that it's not compiled.
I took the src code (a visual studio project) and tried to compile it.
The thing is that I can't link my project to the library.
More specific details are:
What I have already done is the following:
I opened the .sln file and added another sub-project called "Sampler"
I downloaded all Microsoft additional packages that the library src code depends on.
I compiled the library to Windows 32 platform x86 (using Visual Studio 2022). The compilation was successful.
I created a directory Dependencies\OPCClientToolKit in same directory of .sln file, Dependencies\OPCClientToolKit contains two directories include and lib.
I put in Dependencies\OPCClientToolKit\lib the .lib - the output after compilation.
I put in Dependencies\OPCClientToolKit\include the .h files of the src code of sdk library.
I added a dependency .h files via Sampler Project > Properies > C++ General. See pictures below.
I added a dependency folder Dependencies\OPCClientToolKit\lib via Sampler Project > Properies > Linker General. See pictures below.
I added a dependency OPCClientToolKit.lib via Sampler Project > Properies > Linker Input. See pictures below.
As far as I know all my step seems valid and fine.
But when, I am compiling (hitting Build via Visual Studio) the Sampler project code (see the code below) I am getting an error message:
Error Message:
1>------ Build started: Project: Sampler, Configuration: Release Win32 ------
1>Sampler.cpp
1>Sampler.obj : error LNK2001: unresolved external symbol "public: static class COPCHost * __cdecl COPCClient::makeHost(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?makeHost#COPCClient##SAPAVCOPCHost##ABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z)
1>C:\Users\Mark\Desktop\Projects\PID\OPC_DA\Release\Sampler.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Sampler.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please explain to me how should I resolve this issue. I just want to include and use this library and not to modify it.
Dependecies\OPCClientToolKit\lib
Dependecies\OPCClientToolKit\include
Sampler Project > Properties > C++ > General
Sampler Project > Properties > Linker > General
Sampler Project > Properties > Linker > Input
I am using this library (OPC client sdk):
https://sourceforge.net/projects/opcclient/
A usage example made by other guy on the internet:
https://github.com/Tibalt/OPC_DA/blob/master/OPCClientDemo/OPCClientDemo.cpp
My code just use functions and objects of that library.
In details, just trying to initialize opc connection to a server on localhost:
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <sys\timeb.h>
#include "opcda.h"
#include "OPCClient.h"
#include "OPCHost.h"
#include "OPCServer.h"
#include "OPCGroup.h"
#include "OPCItem.h"
using namespace std;
int main(void) {
COPCClient::init();
cout << "Done Init";
cout << endl;
CString hostName = "localhost";
COPCHost* host = COPCClient::makeHost(hostName);
}
That project OPCClientToolKit is very old. It looks like built with using ANSI character set, without using the macro _UNICODE. You should either
Remove the macro _UNICODE from the preprocessor settings in your project.
Or add that entire project OPCClientToolKit as a dependency to your visual studio solution and add the macro _UNICODE to that project.
Or use the solution of that project OPCClientToolKit and rebuild the static library OPCClientToolKit.lib with the macro _UNICODE.

LINK : fatal error LNK1181: cannot open input file 'opencv_world341d.lib'

I have found two similar questions this and this .
But they both use opencv, and opencv indeed provide the corresponding lib. I don't use opencv, and my project is very simple, just hello world.I have changed project default configuration like this
except for these configurations, others all take defaults
I just want to test my project configuration,that works find for win32 debug and release. But not work for x64 debug and release, they all tell me LINK : fatal error LNK1104: cannot open file 'opencv_world341d.lib'
I indeed know my project does not use any opencv lib, but why they tell me I need to use opencv_world341d.lib
my code
#include<iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
}
Thanks for everyone who comments on the question. I have solved the problem, although this problem not relevant to OpenCV to much, but I think the solution to the problem may be helpful to others. When I build project, visual studio 2019 tell me cannot link opencv_world341d.lib, so I go to Project->Properties->Linker->Input->Additional Dependencies , and I found opencv_world341d.lib. So I need to remove it, but it's readonly. From this we know visual studio using settings file (Microsoft.cpp..users.props) to control global settings including Global search path. These files are located at $(USERPROFILE)\appdata\local\microsoft\msbuild\v4.0 directory. Then I reedit Microsoft.cpp.<Platform>.users.props, delete opencv_world341d.lib, reboot visual studio, problem solved.

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>

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.

Can't run simple Visual Studio 2013 project

I was trying to install OpenCV 2411 in Visual Studio 2013, but i receive an error when I try to build the project. The error says: LINK1104: cant open file opencv_core2411.obj
I then decided to check that if I created a simple C++ example without the OpenCV 2411 library and see if i will receive an output. I created a new project to print only the word 'hello', but upon building the project I received the same error message mentioned before: LINK1104: cant open file opencv_core2411.obj despite for that new project that should display 'Hello'; I have not imported the Opencv 2411 libraries.
Why am I receiving that error while the project is never relevant to OpenCV 2411 library?
Try the following steps:
Close and reopen Visual Studio.
Select File -> New Project -> Visual C++ -> Empty Project
Right click source files and select -> Add -> New Item...
Select C++ File (.cpp) and give it a name, i.e. main.cpp
Paste in the "Hello" code (at the bottom of answer)
Press F5 to Start Debugging
Hello Code:
#include <iostream>
int main(){ std::cout << "Hello" << std::endl; return 0; }