Visual Studio C++ cannot find OpenCV-Contrib modules - c++

I am trying to use OpenCV multi-target tracker, but cannot include the header files. I have built OpenCV with extra modules by providing the path to opencv_contrib-4.2.0\modules in OPENCV_EXTRA_MODULES_PATH in CMake GUI. However, I cannot include the trackers in the project:
code:
#include <opencv2/tracking.hpp>
error:
cannot open source file "opencv2/tracking.hpp"
code:
#include "samples_utility.hpp"
error:
Cannot open include file: 'samples_utility.hpp': No such file or directory
What should I do to add all the modules of OpenCV-contrib to the default OpenCV directory?

You don't have to add all the modules. Only the modules you need, and in this case the tracking module. You will need to add the corresponding folder to the include directory and the code should compile properly.(your folder might be in different location but the relative path should be the same)
{location_of_opencv_contrib}\modules\tracking\include
{location_of_opencv_contrib}\modules\tracking\samples
For visual studio, you can add the folder path above to Project Properties-> VC++ Directories -> Include Directories
If you are building using gcc, add -I option followed by the directory of the folder mentioned.

Related

C++ cannot open source file, additional directory listed

I am using Visual Studio 2019, and I'm trying to include codes from open source GLFW. Things were working completely fine, but when I tried to make another project based on this method again it's not working.
It shows 'Cannot open include file: 'GLFW/glfw3.h': No such file or directory'
I reproduced the steps to add GLFW and it worked well. You could check whether there are any missing steps.
Create a Dependencies folder in your project directory, copy the include and lib-vc2019 folders of glfw-3.3.2.bin.WIN32 to Dependencies.
Set Configuration to All Configurations and set Platform to Win32
Add $(SolutionDir)Dependencies\GLFW\include in Proeperties->C/C++->General->Additional Include Directories
Add $(SolutionDir)Dependencies\GLFW\lib-vc2019 in Proeperties->Linker->General->Additional Library Directories
Add glfw3.lib;opengl32.lib;User32.lib;Gdi32.lib;%(AdditionalDependencies) in Proeperties->Linker->Input->Additional Dependencies

Visual Studio C++ how to add header files in a prefix folder

I cloned a github C++ repository. The repository is not a VS project. So I manually created a VS C++ blank project and added the files from the repo to the project. The files are not copied. This is not the problem.
The repo directory looks like this:
include\NTL\*.h
src\*.cpp
*.h means a bunch of header files and *.cpp means a bunch of .cpp source files.
The problem is that the .cpp files have #include <NTL/*.h> and when I build, VS fails to locate the header files (No such file or directory). Adding the path to the include to the Include Directories in project properties didn't help.
EDIT: After some experimenting, I've found that the error has nothing to do with the prefix NTL in #include <NTL/*.h> but with whether the files are copied into project directory. Even though the files appear in VS project view, they must be copied into the project directory.
EDIT: The only way I've managed to get the project to compile is to put the whole NTL directory containing header files in project directory. Include Directories and Additional Include Directories in project properties don't seem to have any effect.
All previous No such file or directory errors were the result of some combination of:
Mismatching project properties Configuration and Platform
Some .h files were actually missing from NTL github repo, e.g. mach_desc.h.
The solution to the problem consists of the following:
Under project Properties > C/C++, add the path to the include to Additional Include Directories.
VS project has a separate set of properties for each combination of Configuration and Platform. Make sure that step 1 applies to the active Configuration and Platform. E.g. If the project's currently configured to build for Debug x64 (active Configuration:Debug and Platform:x64), make sure that step 1 applies to Debug x64, and not something like Release Win32 or Release x64, etc.
Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

Boost C++ Libaries in Visual Studio 2017 C++ Project - "Cannot open include file"

I'm trying to add the Boost C++ Libraries to my C++ project created with Visual Studio 2017.
I have followed the instructions here.
When that didn't work I tried the advice in this post. Neither solutions worked for me.
What I have done:
Downloaded boost_1_69_0-msvc-14.1-64.exe from this precompiled boost libraries page
Installed to D:\local\boost_1_69_0
In my project I added D:\local\boost_1_69_0 to Properties > VC++ Directories > Include Directories and added D:\local\boost_1_69_0\lib64-msvc-14.1 to Properties > VC++ Directories > Library Directories
I have my project set to x64 and the above settings were set in the x64 configuration
When I try to build my project I get this error:
Error C1083 Cannot open include file: 'boost/regex.hpp': No such file or directory
Which points to this line of code in one of my .cpp files:
#include <boost/regex.hpp>
Please go to D:\local\boost_1_69_0 folder and see if you have a sub-folder named include in there. If you do, then instead of D:\local\boost_1_69_0 you need to set D:\local\boost_1_69_0\include in Properties > VC++ Directories > Include Directories
In other words, try to find the file you are including on your hard drive. Look at the full path to the file. Compare that full path with the path you added to the list of include directories (Properties > VC++ Directories > Include Directories) concatenated with the relative path you provided just before the filename in your include directive (boost). See if the two are the same.
If that does not help, then make sure you changed list of include directories for the same build configuration as you are attempting to build (if you build Debug, make sure you changed configuration for Debug too). Since VS 2015 IDE stopped making sure the two are selected in sync, which is annoying.
If your files are copied, then you have to compile the regular library.... If the same version of the compiler copies the machine.
Found out it was failing because I had included the same .cpp file which has the boost include into my unit test project which did NOT have the Include/Library folders set. The settings in my original question work now.

How to create a simple CLion C++ CMake project with different locations for Project itself, build products and source files

I'm new with CLion and CMakeList. I'd like to have different locations for:
CLion project files
Build Files
Source and Header Files
When opening default projects all are located under the same directory tree
What are the steps to create such project ('Hello world')?
CLion project files
AFAIK, you can only set one global path for each jetbrains' IDE, by writing IDE_HOME\bin\idea.properties file.
Details can be found here.
Build Files
Settings -> Build, Execution, Deployment -> CMake -> Generation path
You can also set several paths for different build profiles there.
Source and Header Files
Add sources and include directories in CMakeLists.txt .

How to add Qt libraries to visual studio

I have a source with VC++ 2017
I receive the error "Error C1083 Cannot open include file: 'QtCore/QMap': No such file or directory " when i try compile the project.
I download Qt libraries and add to Include project but the problem exist.
Which directory of Qt of i had to add to project to resolve error?
this is header of my code that generate error
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QList>
You need to update your project. Go to the project properties by right-clicking on it in Solution Explorer and then select Properties. Then:
In C/C++->General->Additional Include Directories you must set the Qt installation include path;
In Linker->General->Additional Library Directories you must add the path of .libs files of your qt installation;
In Linker->Input->Additional Dependencies you must put the name of .lib files that you need in order to build the project.
If it's a Qt project, you should also have the Qt plugin installed, in order to work properly with moc and other Qt features.
In alternative (that I suggest) you can create a CMake project and open in in Visual Studio.