How to integrate CryptoPP in Visual Studio C++ (2019) - c++

I have some problems integrating CryptoPP in Visual Studio. I've followed some tutorials without success, and when I try to compile the project I get hundreads of errors.
What I did:
I builded cryptlib with both debug and release configurations, generating the cryptlib.lib files
I added the dependencies to the .lib files that I've just generated
I added the paths to the .h files
When compiling my project, I get more than 100 errors of the type LNKxxxx, I don't know if I did something wrong while compiling the libraries, or if I miss something, but I'm completely stuck.
--- EDIT ---
As requested, here are some of the errors I get
Error LNK2038 mismatch detected for 'RuntimeLibrary': the value
'MTd_StaticDebug' does not match the value 'MDd_DynamicDebug' in
pwmc.obj pwmc C:\Users\aless\Documents\C\pwm\pwmc\pwmc\cryptlib.lib(rijndael.obj) 1
Error LNK2005 "protected: __cdecl std::basic_streambuf<char,struct
std::char_traits >::basic_streambuf<char,struct
std::char_traits >(void)"
(??0?$basic_streambuf#DU?$char_traits#D#std###std##IEAA#XZ) already
defined in
cryptlib.lib(cryptlib.obj) pwmc C:\Users\aless\Documents\C\pwm\pwmc\pwmc\msvcprtd.lib(MSVCP140D.dll) 1
Error LNK2005 "private: static class std::locale::_Locimp * __cdecl
std::locale::_Init(bool)" (?_Init#locale#std##CAPEAV_Locimp#12#_N#Z)
already defined in
msvcprtd.lib(MSVCP140D.dll) pwmc C:\Users\aless\Documents\C\pwm\pwmc\pwmc\libcpmtd.lib(locale0.obj) 1
Since my Visual Studio is not in english I translated the errors myself, but I don't know the exact/correct translation, I hope that is clear enough anyway.
Thanks in advance to everyone.
PS
I don't think my code is the problem, to test if all were working i used this sample code

Related

Libcpmt.lib: Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'

While compiling a current project I get a bunch (about 80) of Linker errors that I don't know anymore how to debug further.
I am using Visual Studio 2019. It's a C++ project compiled on Windows 10.
A lot of them come from a library called libcpmt.lib.
There are 2 types of error related to the library:
First it claims some function s are alredy defined in msvcprt.lib(MSVCP140.dll) (which is strange since I am using Visual Studio 2019 v142)
Error LNK2005 "protected: __cdecl std::locale::facet::facet(unsigned __int64)" (??0facet#locale#std##IEAA#_K#Z) already defined in msvcprt.lib(MSVCP140.dll) DataConverter path_to_project\libcpmt.lib(locale0.obj)
and second it claims that libcpmt.lib is compiled statically while my project used dynamically linked libraries.
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in annotation.obj DataConverter path_to_project\libcpmt.lib(xstol.obj) 1
The same error also appears on a library called mpirxx.lib
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in annotation.obj DataConverter path_to_project\mpirxx.lib(osmpf.obj) 1
and
Error LNK2005 "public: void __cdecl std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx#?$basic_ostream#DU?$char_traits#D#std###std##QEAAXXZ) already defined in mpirxx.lib(osmpf.obj) DataConverter path_to_project\msvcprt.lib(MSVCP140.dll) 1
From what little I found about the lib on the internet it appears to be included when your C++->Code Generation->Runtime Library is set to MT, but my settings are set to MD.
I am including a lot of external libraries in my project:
flann.lib
flann_cpp.lib
Qt5Widgets.lib
qtmain.lib
Qt5Gui.lib
Qt5Core.lib
libboost_atomic-vc142-mt-x64-1_74.lib
libboost_chrono-vc142-mt-x64-1_74.lib
libboost_container-vc142-mt-x64-1_74.lib
libboost_context-vc142-mt-x64-1_74.lib
libboost_contract-vc142-mt-x64-1_74.lib
libboost_coroutine-vc142-mt-x64-1_74.lib
libboost_date_time-vc142-mt-x64-1_74.lib
libboost_exception-vc142-mt-x64-1_74.lib
libboost_fiber-vc142-mt-x64-1_74.lib
libboost_graph-vc142-mt-x64-1_74.lib
libboost_iostreams-vc142-mt-x64-1_74.lib
libboost_locale-vc142-mt-x64-1_74.lib
libboost_log_setup-vc142-mt-x64-1_74.lib
libboost_log-vc142-mt-x64-1_74.lib
libboost_math_c99f-vc142-mt-x64-1_74.lib
libboost_math_c99l-vc142-mt-x64-1_74.lib
libboost_math_c99-vc142-mt-x64-1_74.lib
libboost_math_tr1f-vc142-mt-x64-1_74.lib
libboost_math_tr1l-vc142-mt-x64-1_74.lib
libboost_math_tr1-vc142-mt-x64-1_74.lib
libboost_nowide-vc142-mt-x64-1_74.lib
libboost_numpy37-vc142-mt-x64-1_74.lib
libboost_prg_exec_monitor-vc142-mt-x64-1_74.lib
libboost_program_options-vc142-mt-x64-1_74.lib
libboost_python37-vc142-mt-x64-1_74.lib
libboost_random-vc142-mt-x64-1_74.lib
libboost_regex-vc142-mt-x64-1_74.lib
libboost_serialization-vc142-mt-x64-1_74.lib
libboost_stacktrace_noop-vc142-mt-x64-1_74.lib
libboost_stacktrace_windbg_cached-vc142-mt-x64-1_74.lib
libboost_stacktrace_windbg-vc142-mt-x64-1_74.lib
libboost_system-vc142-mt-x64-1_74.lib
libboost_test_exec_monitor-vc142-mt-x64-1_74.lib
libboost_thread-vc142-mt-x64-1_74.lib
libboost_timer-vc142-mt-x64-1_74.lib
libboost_type_erasure-vc142-mt-x64-1_74.lib
libboost_unit_test_framework-vc142-mt-x64-1_74.lib
libboost_wave-vc142-mt-x64-1_74.lib
libboost_wserialization-vc142-mt-x64-1_74.lib
bz2.lib
libpng16.lib
lz4.lib
lzma.lib
mpfr.lib
mpir.lib
mpirxx.lib
qhullcpp.lib
xxhash.lib
zlib.lib
zstd.lib
gmp.lib
glew32.lib
glew32s.lib
opencv_world440.lib
vtkChartsCore-9.0.lib
vtkCommonColor-9.0.lib
vtkCommonComputationalGeometry-9.0.lib
vtkCommonCore-9.0.lib
vtkCommonDataModel-9.0.lib
vtkCommonExecutionModel-9.0.lib
vtkCommonMath-9.0.lib
vtkCommonMisc-9.0.lib
vtkCommonSystem-9.0.lib
vtkCommonTransforms-9.0.lib
vtkDICOMParser-9.0.lib
vtkDomainsChemistry-9.0.lib
vtkdoubleconversion-9.0.lib
vtkexodusII-9.0.lib
vtkexpat-9.0.lib
vtkFiltersAMR-9.0.lib
vtkFiltersCore-9.0.lib
vtkFiltersExtraction-9.0.lib
vtkFiltersFlowPaths-9.0.lib
vtkFiltersGeneral-9.0.lib
vtkFiltersGeneric-9.0.lib
vtkFiltersGeometry-9.0.lib
vtkFiltersHybrid-9.0.lib
vtkFiltersHyperTree-9.0.lib
vtkFiltersImaging-9.0.lib
vtkFiltersModeling-9.0.lib
vtkFiltersParallel-9.0.lib
vtkFiltersParallelImaging-9.0.lib
vtkFiltersPoints-9.0.lib
vtkFiltersProgrammable-9.0.lib
vtkFiltersSelection-9.0.lib
vtkFiltersSMP-9.0.lib
vtkFiltersSources-9.0.lib
vtkFiltersStatistics-9.0.lib
vtkFiltersTexture-9.0.lib
vtkFiltersTopology-9.0.lib
vtkFiltersVerdict-9.0.lib
vtkfreetype-9.0.lib
vtkGeovisCore-9.0.lib
vtkgl2ps-9.0.lib
vtkglew-9.0.lib
vtkhdf5-9.0.lib
vtkhdf5_hl-9.0.lib
vtkImagingColor-9.0.lib
vtkImagingCore-9.0.lib
vtkImagingFourier-9.0.lib
vtkImagingGeneral-9.0.lib
vtkImagingHybrid-9.0.lib
vtkImagingMath-9.0.lib
vtkImagingMorphological-9.0.lib
vtkImagingSources-9.0.lib
vtkImagingStatistics-9.0.lib
vtkImagingStencil-9.0.lib
vtkInfovisCore-9.0.lib
vtkInfovisLayout-9.0.lib
vtkInteractionImage-9.0.lib
vtkInteractionStyle-9.0.lib
vtkInteractionWidgets-9.0.lib
vtkIOAMR-9.0.lib
vtkIOAsynchronous-9.0.lib
vtkIOCityGML-9.0.lib
vtkIOCore-9.0.lib
vtkIOEnSight-9.0.lib
vtkIOExodus-9.0.lib
vtkIOExport-9.0.lib
vtkIOExportGL2PS-9.0.lib
vtkIOExportPDF-9.0.lib
vtkIOGeometry-9.0.lib
vtkIOImage-9.0.lib
vtkIOImport-9.0.lib
vtkIOInfovis-9.0.lib
vtkIOLegacy-9.0.lib
vtkIOLSDyna-9.0.lib
vtkIOMINC-9.0.lib
vtkIOMotionFX-9.0.lib
vtkIOMovie-9.0.lib
vtkIONetCDF-9.0.lib
vtkIOOggTheora-9.0.lib
vtkIOParallel-9.0.lib
vtkIOParallelXML-9.0.lib
vtkIOPLY-9.0.lib
vtkIOSegY-9.0.lib
vtkIOSQL-9.0.lib
vtkIOTecplotTable-9.0.lib
vtkIOVeraOut-9.0.lib
vtkIOVideo-9.0.lib
vtkIOXML-9.0.lib
vtkIOXMLParser-9.0.lib
vtkjpeg-9.0.lib
vtkjsoncpp-9.0.lib
vtklibharu-9.0.lib
vtklibproj-9.0.lib
vtklibxml2-9.0.lib
vtkloguru-9.0.lib
vtklz4-9.0.lib
vtklzma-9.0.lib
vtkmetaio-9.0.lib
vtknetcdf-9.0.lib
vtkogg-9.0.lib
vtkParallelCore-9.0.lib
vtkParallelDIY-9.0.lib
vtkpng-9.0.lib
vtkpugixml-9.0.lib
vtkRenderingAnnotation-9.0.lib
vtkRenderingContext2D-9.0.lib
vtkRenderingCore-9.0.lib
vtkRenderingFreeType-9.0.lib
vtkRenderingGL2PSOpenGL2-9.0.lib
vtkRenderingImage-9.0.lib
vtkRenderingLabel-9.0.lib
vtkRenderingLOD-9.0.lib
vtkRenderingOpenGL2-9.0.lib
vtkRenderingSceneGraph-9.0.lib
vtkRenderingUI-9.0.lib
vtkRenderingVolume-9.0.lib
vtkRenderingVolumeOpenGL2-9.0.lib
vtkRenderingVtkJS-9.0.lib
vtksqlite-9.0.lib
vtksys-9.0.lib
vtkTestingRendering-9.0.lib
vtktheora-9.0.lib
vtktiff-9.0.lib
vtkverdict-9.0.lib
vtkViewsContext2D-9.0.lib
vtkViewsCore-9.0.lib
vtkViewsInfovis-9.0.lib
vtkWrappingTools-9.0.lib
vtkzlib-9.0.lib
pcl_common.lib
pcl_features.lib
pcl_filters.lib
pcl_io.lib
pcl_io_ply.lib
pcl_kdtree.lib
pcl_keypoints.lib
pcl_ml.lib
pcl_octree.lib
pcl_recognition.lib
pcl_registration.lib
pcl_search.lib
pcl_segmentation.lib
pcl_sample_consensus.lib
pcl_stereo.lib
pcl_surface.lib
pcl_tracking.lib
Does anybody have an idea how to further debug or fix these issues?
PS: I currently have another error which is likely unrelated but I wanted to include it for completeness. The linker can't find the lib for loadPolygonFilePLY. Likely I'm just missing an additional pcl lib. If anybody happens to know how it's called please also comment:
Error LNK2001 unresolved external symbol "int __cdecl pcl::io::loadPolygonFilePLY(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct pcl::PolygonMesh &)" (?loadPolygonFilePLY#io#pcl##YAHAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEAUPolygonMesh#2##Z)
In case somebody comes along a similar issue. These was a library in my included libraries that was using the static linkage (mpirxx.lib). A good way to debug this is to put /VERBOSE:LIB in your linker options. Then build and go to your Output windows where you can see which is the first library to trigger this error chain.
Thanks to Alan Birtles for the help.

LINK2001 When Building Visual Studio Project, BGSLIbrary, where is Linker in v2017

I am trying to build the BGSLibrary for Windows 10, cmake 3.9, with python support, built with opencv 3.1 and boost 1.64.0 with Visual Studio Community 2017.
Can someone more familiar with Visual Studio interpret this error for me. The c++ seems to compile great, but then project solution fails. It starts by building all the .obj files
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\Lib.exe /OUT:"C:\Users\Ben\Documents\bgslibrary\build\libbgs.lib" /NOLOGO /machine:X86 libbgs.dir\Release\AdaptiveBackgroundLearning.obj
2>libbgs.dir\Release\AdaptiveSelectiveBackgroundLearning.obj
2>libbgs.dir\Release\CodeBook.obj
2>libbgs.dir\Release\DPAdaptiveMedian.obj
2>libbgs.dir\Release\DPEigenbackground.obj
The general error reads.
5>libbgs.lib(LBSP.obj) : error LNK2019: unresolved external symbol "public: virtual void __thiscall cv::Feature2D::read(class cv::FileNode const &)" (?read#Feature2D#cv##UAEXABVFileNode#2##Z) referenced in function "[thunk]:public: virtual void __thiscall cv::Feature2D::read`vtordisp{4294967292,0}' (class cv::FileNode const &)" (?read#Feature2D#cv##$4PPPPPPPM#A#AEXABVFileNode#2##Z)
But the file LBSP.obj compiled fine just 100 lines earlier? I can see it here.
This file was created during the build, why can't it link? Where do I need to add this dir?
I'm reading other SO questions that this error may mean I need to add additional paths, which was done pre-VS2017 by going to PROPERTIES->LINKER->ADDITIONAL DEPENDENCIES. I don't see this option or structure anymore.
3>C:\Users\Ben\Documents\opencv\modules\core\include\opencv2/core/types_c.h(894)
This was a Cmake path error, not a Visual Studio error. Adding OpenCV/bin to path solved this.

Error C4996 on using boost example

I have installed Boost 1.58.0 following their instructions and the examples they give in the installation guide work fine using VS2012. I also have OpenCV3.0.0 included in my properties. I want to check out an example of some graphing functions, so I copied this code: http://www.boost.org/doc/libs/1_58_0/libs/graph/example/astar_maze.cpp , and included stdafx.h on the top.
When compiling, I get
error C4996: 'std::_Fill_n': Function call with parameters that may be unsafe
Other people suggest either using
#pragma warning( disable : 4996 )
which doesn't seem to change anything, or turning off SDL checks via properties, which turns the error into a warning, but gives me many more errors, mostly LNK2005.
Any ideas how to get the code running?
Additional info:
Types of error when turning off SDL checks are (my project is BoostExample):
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in BoostExample.obj
error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12#std##QAE#XZ) already defined in opencv_ts300d.lib(ts_perf.obj)
error LNK2005: ___crtSetUnhandledExceptionFilter already defined in MSVCRTD.lib(MSVCR110D.dll)
and finally
fatal error LNK1169: one or more multiply defined symbols found
I guess this means that Boost is interacting with OpenCV and other DLLs by redefining something. Is it possible that I installed the wrong boost version? I just grabbed the main one.
The linker error tells basically the boost and the OpenCV were compiled off using different runtime settings, one for static lib and the other for DLL, and cannot be mixed used. you need to rebuild your boost and OpenCV to use same runtime setting.

Compile Tesseract for Visual Studio 2013

I'm trying to use the tesseract in visual studio 2013. I'm using "libtesseract302.lib" in the the linker -> Input (not "libtesseract302-static.lib") and everythings was OK, and it's compiled and run, but when I tried to use this code:
tesseract::ResultIterator* ri;
tesseract::ChoiceIterator ci(*ri);
I got five link errors like this:
Error 3 error LNK2028: unresolved token (0A000567)
"public: __thiscall tesseract::ChoiceIterator::ChoiceIterator
(class tesseract::LTRResultIterator const &)"
(??0ChoiceIterator#tesseract##$$FQAE#ABVLTRResultIterator#1##Z)
referenced in function "int __cdecl main(void)" (?main##$$HYAHXZ)
I think it's because I didn't use the static library, so I tried that, but I got many linking errors. I think that is due to the static library having been built before using vs2008 that I got from here.
Tesseract
So I'm trying now to compile the tesseract as static lib in vs2013. Will solve the issue, or should I try something else?

Error in DirectX example from Microsoft

I'm trying to learn C++ and DirectX, got VS 2012 Express Desktop today for Windows 7. I should probably mention I already had DirectX SDK for VS 2010 installed.
The first of the 7 tutorials will compile fine, the rest are giving errors. Because the first one runs I think my include and library directories are set up fine.
Source is here, I put the .fx file in at the bottom as well as the compiler errors. If you don't want to click megafileupload it's just the DirectX draw a triangle tutorial (2) from Microsoft.
Tutorial files on megaupload
Warning 1 warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification C:\cpp\DirectX_Tutorial\C++\Tutorial02\Tutorial02.obj Tutorial02
Error 2 error LNK2019: unresolved external symbol _D3DCompileFromFile#36 referenced in function "long __cdecl CompileShaderFromFile(wchar_t *,char const *,char const *,struct ID3D10Blob * *)" (?CompileShaderFromFile##YAJPA_WPBD1PAPAUID3D10Blob###Z) C:\cpp\DirectX_Tutorial\C++\Tutorial02\Tutorial02.obj Tutorial02
Error 3 error LNK1120: 1 unresolved externals C:\cpp\DirectX_Tutorial\C++\Debug\Tutorial02.exe Tutorial02
Also is there a forum here I can rant on? C++, the Windows API, DirectX, and Visual Studio are all just so unnecessarily difficult to use.
Recheck if your import libraries are correct and if you're importing from the folder corresponding to your processor architecture.
Also, double check project's encoding, directx doesnt usually work well on encodings other than Unicode.