How to Add Library to Visual Studio - OpenCV - c++

Im trying to add OpenCV to Visual Studio, and afer following the instructions from this video: https://www.youtube.com/watch?v=unSce_GPwto&ab_channel=BoostMyTool , it returned that it was not built succesfuly.
To start off, what i have already done:
I added Path to Enviroment Variables
added the path "C:\Users\Uporabnik\Documents\Library\opencv\build\ include" to
project/properties/c#c++/general/addittional include directories
added the path "C:\Users\Uporabnik\Documents\Library\opencv\build\x64\vc15\ lib" to project/properties/linker/general/addittional library directories
added "opencv_world460.lib" to project/properties/linker/input/addittional dependencies
when all was done, i ran the build solution and it returnes not succesfull.
im used to python on PyCharm, where adding libraries is as easy ass pressing add library, so this has been an annoying experiance so far
the error message after "build/build solution":
Build started...
1>------ Build started: Project: hhh, Configuration: Release x64 ------
1>hhh.cpp
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(11,39): error C2065: 'CV_CAP_PROP_FRAME_COUNT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(12,45): error C2065: 'CV_CAP_PROP_FRAME_COUNT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(20,40): error C2065: 'CV_CAP_PROP_FRAME_WIDTH': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(20,79): error C2065: 'CV_CAP_PROP_FRAME_HEIGHT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(21,46): error C2065: 'CV_CAP_PROP_FRAME_WIDTH': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(21,88): error C2065: 'CV_CAP_PROP_FRAME_HEIGHT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(23,62): error C3861: 'CV_FOURCC': identifier not found
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(53,1): error C2018: unknown character '0x60'
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\hhh.cpp(53,2): error C2018: unknown character '0x60'
1>main.cpp
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(11,39): error C2065: 'CV_CAP_PROP_FRAME_COUNT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(12,45): error C2065: 'CV_CAP_PROP_FRAME_COUNT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(20,40): error C2065: 'CV_CAP_PROP_FRAME_WIDTH': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(20,79): error C2065: 'CV_CAP_PROP_FRAME_HEIGHT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(21,46): error C2065: 'CV_CAP_PROP_FRAME_WIDTH': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(21,88): error C2065: 'CV_CAP_PROP_FRAME_HEIGHT': undeclared identifier
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(23,62): error C3861: 'CV_FOURCC': identifier not found
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(53,1): error C2018: unknown character '0x60'
1>C:\Users\Uporabnik\Desktop\C#\hhh\hhh\main.cpp(53,2): error C2018: unknown character '0x60'
1>Done building project "hhh.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Elapsed 00:04,338 ==========

Well, that's an error compiling, not a linker error, so it can be relatively few things.
Verify that hhh.cpp and main.cpp include the correct OpenCV header(s).
Verify those headers are actually in C:\Users\Uporabnik\Documents\Library\opencv\build\includeor are in folders accessible by relative paths rooted there that correspond to the relative paths in your include directives.
Verify you have added that path to "Additional Include Directories" in the properties of the configuration you are trying to build.
Without additional information my guess would be your problem is 3. The "configuration" in Visual Studio is typically a pair of parameters, either Debug or Release along with the architecture, x86 (often displayed as "Win32" in VS) or x64. I can see from the error messages you are trying to build "Release x64".
Go into properties and make sure you have made the addition to "Additional Include Directories" in the configuration "Release x64". It is an easy mistake to make to accidently set properties only for Debug or only for x86, etc.

Related

Using vcpkg and compiling in Visual Studio 2015

I am trying to compile (by porting) some code in Windows 10 that was originally developed for Linux.
The code depends on 2 external libraries: cppkafka and librdkafka.
I saw that vcpkg is able to get the libraries, compile them, and then make them automatically available in Visual Studio 2015 (through the vcpkg integrate install command).
I see that the vcpkg compiles the dependencies for windows 64 (cppkafka and librdkafka) properly, as the .dll, .lib... are all made available on the install folder of vcpkg.
When I try compiling my code in Visual Studio 2015, I see errors concerning the dependencies headers, which for me is unexpected. If vcpkg compiled them, why Visual Studio doesn't? From the vcpkg documentation, I assume they use the same compiler. Next I show some example errors I am getting:
1>------ Build started: Project: AndreKafkaDriver, Configuration: Release x64 ------
1>C:\...\vcpkg\installed\x64-windows\include\librdkafka/rdkafka.h(64): error C2371: 'ssize_t': redefinition; different basic types
1> C:\Siemens\Automation\WinCC_OA\3.16\api\include\winnt\win32.h(47): note: see declaration of 'ssize_t'
1>c:\...\vcpkg\installed\x64-windows\include\cppkafka\header_list.h(265): warning C4267: 'argument': conversion from 'size_t' to 'ssize_t', possible loss of data
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'queue1': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'queue2': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'mutex': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2275: 'std::mutex': illegal use of this type as an expression
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): note: see declaration of 'std::mutex'
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2182: 'swap_queues': illegal use of type 'void'
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2470: 'cppkafka::BufferedProducer<BufferType,Allocator>::swap_queues': looks like a function definition, but there is no parameter list; skipping apparent body
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2072: 'cppkafka::BufferedProducer<BufferType,Allocator>::swap_queues': initialization of a function
1>kafkaHWService.cxx(29): fatal error C1083: Cannot open include file: 'execinfo.h': No such file or directory
...
Thanks in advance,
Nerea

building example of canopen from canfestival error

I've got canopen source from canfestival.
I got errors when I built its win32test example on visual stdio,
there wasn't any lib file in file that I downloaded and extracted.
any help would be appreciated.
the errors:
error C2065: 'win32test_obj100C': undeclared identifier
error C2065: 'win32test_obj100D': undeclared identifier
there was a problem in built object dictionary
I make another object dictionary header and source with its .od file in cygwin and the errors gone

Tesseract 3.05 Build errors in Visual Studio 2017

I used the solution provided here in order to make Tesseract 3.05 work on my windows10 x64 project, visual studio 2017.
I got these errors when building it:
11>c:\users\mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unichar.h(164): error C3646: 'UTF32ToUTF8': unknown override specifier
11>c:\users\mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unichar.h(164): error C2059: syntax error: 'const'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unichar.h(164): error C2238: unexpected token(s) preceding ';'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\genericvector.h(376): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\params.h(205): warning C4800: 'BOOL8': forcing value to bool 'true' or 'false' (performance warning)
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(241): error C3646: 'CleanupString': unknown override specifier
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(241): error C2059: syntax error: 'const'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(241): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(244): error C3646: 'CleanupString': unknown override specifier
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(244): error C2059: syntax error: 'const'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(244): error C2238: unexpected token(s) preceding ';'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(265): error C2065: 'string': undeclared identifier
11>c:\users\mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(265): error C2146: syntax error: missing ';' before identifier 'cleaned'
11>c:\users\ mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(265): error C2065: 'cleaned': undeclared identifier
11>c:\users\mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(265): error C3861: 'CleanupString': identifier not found
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\unicharset.h(266): error C2065: 'cleaned': undeclared identifier
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(181): error C3646: 'VersionString': unknown override specifier
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(181): error C2059: syntax error: '('
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(181): error C2238: unexpected token(s) preceding ';'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(183): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(183): error C2143: syntax error: missing ',' before '&'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(134): error C2664: 'void tesseract::TessdataManager::SetVersionString(const int)': cannot convert argument 1 from 'const char [13]' to 'const int'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(134): note: There is no context in which this conversion is possible
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(138): error C2664: 'void tesseract::TessdataManager::SetVersionString(const int)': cannot convert argument 1 from 'const char [13]' to 'const int'
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\ccutil\tessdatamanager.h(138): note: There is no context in which this conversion is possible
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\dict\dict.h(55): warning C4566: character represented by universal-character-name '\u2606' cannot be represented in the current code page (1252)
11>c:\users\jihed mestiri\documents\vs2015_tesseract-master\vs2015_tesseract-master\tesseract_3.05\api\tesseractmain.cpp(34): fatal error C1083: Cannot open include file: 'simddetect.h': No such file or directory
11>Done building project "tesseract.vcxproj" -- FAILED.
========== Build: 9 succeeded, 2 failed, 0 up-to-date, 0 skipped ==========
How to resolve them?
Since the time of the linked answer, project structure was changed. It's updated to Tesseract 3.05 and clear Git submodule links to the proper Leptonica and tesseract_3.05 sources added.
It looks like you've downloaded master sources for both of them. At the moment VS2015_Tesseract is not compatible with it.
Proper dependency links are: leptonica # e98a794 and tesseract_3.05 # 7fe95f0. Download it and try to rebuild the solution.
After adding in C/C++ -> Additional Include libraries:
C:\Users\Jihed Mestiri\Documents\VS2015_Tesseract-master\liblept
C:\Documents\VS2015_Tesseract-master\leptonica\src
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\wordrec
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\opencl
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\viewer
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\textord
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\neural_networks\runtime
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\dict
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\cutil
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\cube
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\classify
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\ccstruct
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\ccutil
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\ccmain
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\api
C:\Users\Documents\VS2015_Tesseract-master\tesseract_3.05\vs2010\port
as well as the directory that contains .lib files in Linker -> General -> Additional Library directories and included in Linker -> Input -> Additional dependencies these .lib files of Tesseract and Leptonica:
libtesseract.lib
giflib.lib
libjpeg.lib
liblept.lib
libpng.l‌​ib
libtiff.lib
li‌​bwe‌​bp.lib
openjpeg.lib
‌​zlib.lib
Compilation errors of my test program changed to:
1>------ Build started: Project: RedEyeRemover, Configuration: Debug x64 ------
1>LINK : fatal error LNK1104: cannot open file 'libpng.l‌​ib'
1>Done building project "RedEyeRemover.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Whereas the directory that contains libpng.lib file is included in Linker->General.
The parameters are taken from tesseract/tesseract.vcxproj that I build from VS2015_Tesseract
What can be the reason behind that error? and is there a way to verify that tesseract.vcxproj is working correctly at its own? because I get errors when I compile it too on Visual Studio 2017 (using v140 = VS 2015 version for build) on x64 target.
EDIT: SOLUTION: I discovered that the problem was in Linker -> General -> Additional Library directories where I had a space in one of the parent directory of the path e.g: "xxx xxx/tesseract". => avoid using paths with space.

#include <Dbghelp.h> doesn't include the header

If you include #include <Dbghelp.h> in, for example, a console C++ application, it will not bring any definitions from the header file and there are more or less similar compiler errors as if this header is not included at all.
Compiler errors looks like:
1>------ Build started: Project: ConsoleDump, Configuration: Debug Win32 ------
1> ConsoleDump.cpp
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C2146: syntax error: missing ';' before identifier 'Flags'
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C2065: 'Flags': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C2065: 'MiniDumpWithFullMemory': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(24): error C2065: 'MiniDumpWithFullMemoryInfo': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(25): error C2065: 'MiniDumpWithHandleData': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(26): error C2065: 'MiniDumpWithUnloadedModules': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(27): error C2065: 'MiniDumpWithThreadInfo': undeclared identifier
What's going wrong?
You must included <windows.h> before <DbgHelp.h>, and if the project uses "Stdafx.h", it must be included before everything else. The following is the correct order:
#include "stdafx.h"
#include <windows.h>
#include <Dbghelp.h>
Also make sure to link DbgHelp.lib to 'Project settings' > Linker > Input > 'Additional Dependencies'.

Online JTAG / RGH Source Code Compile Time Errors

I am trying to compile this source for the JTAG/RGH online server method. I got errors when trying to compile. Below is the output error log.
1>------ Build started: Project: client, Configuration: Debug Win32 ------
1> CAssemblerDlg.cpp
1>e:\jtag\socket server\socket server\windows\cassemblerdlg.cpp(104): error C2065: 'm_hListControl' : undeclared identifier
1>e:\jtag\socket server\socket server\windows\cassemblerdlg.cpp(107): error C2065: 'm_hListControl' : undeclared identifier
1>e:\jtag\socket server\socket server\windows\cassemblerdlg.cpp(110): error C2065: 'm_hListControl' : undeclared identifier
1>e:\jtag\socket server\socket server\windows\cassemblerdlg.cpp(113): error C2065: 'm_hListControl' : undeclared identifier
1>e:\jtag\socket server\socket server\windows\cassemblerdlg.cpp(114): error C2065: 'm_hListControl' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If anyone can help me it would be great.
It seems that you forgot to include some headers where m_hListControl were declared.
I'm saying so, because m_* prefix often used for class private members.
Here is extract from MSDN:
Compiler Error C2065
A variable's type must be specified in a declaration before it can be used. The parameters that a function uses must be specified in a declaration, or prototype, before the function can be used.
Possible causes:
Omitting necessary include files.
Identifier name is misspelled.
Identifier uses the wrong uppercase and lowercase letters.
Missing closing quote after a string constant.
Improper namespace scope.