Include OpenCV for Project in C++ - c++

I feel like this should be basic, but I can't find anything for it online. I downloaded OpenCV and can't figure out how to have my projects recognize it. When I try to include it with like
#include <opencv2/core/version.hpp>
I get the error:
"No such file or directory"
The only solution I've tried is to add /usr/include/opencv4/ to my PATH. Also, I am running ArchLinux if that is helpful to know.

So I ended up just moving the directory /usr/include/opencv4/opencv2 to /usr/include and that worked. Unless there are any ways to add directories to the list of directories that c++ checks when running the #include, this is the only way I've figured to solve it.

if you have trouble with this
#include <opencv2/core/version.hpp>
You can find more detail information on "Googling".
what I have organized shown below:
try using include "opencv2/core/version.hpp" instead of it.
right-click, then check-the-location
recheck several environment settings:
Additional Include Directories
Linker
Additional Dependencies
PATH

Try changing these three:
PATH=$PATH:/usr/bin
CPATH=$CPATH:/usr/include/opencv4
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:/usr/lib

Related

Eclipse C++: fatal error: cheddar.h: no such file or directory

[RHEL v7.3, Eclipse Photon, C/C++ Project with Eclipse-generated Makefile]
Attempting to include a custom library named cheddar.h results in
Fatal Error: cheddar.h: no such file or directory
Research 1 and 2 suggests manually adding the include path by first alt-clicking the project in Project Explorer, and then manually adding the path :
Properties -> C/C++ General -> Paths and Symbols : Includes : Languages, GNU C++
No luck.
It works if I do things the old-fashioned way, and add the path to the makefile with a -I option, like so
-I/home/kmiklas/lib/
..but I feel like I'm working-around the issue, and I want this set up properly; the way it should be set up.
How do I correctly specify a custom include path in Eclipse? Tyvm :^)
What is wrong with CMake/Makefile?
I don’t know, but this just sounds like an XY problem. But what’s even more confusing is how you’re so reluctant to use a solution that you’ve already got (as in it’s bugging me).
Anyway
What may aid you in this is to ditch eclipse’s settings and just use the compiler’s. Eclipse uses (GCC/G++ (probably)). What you can do is set some environment variables DUN DUN DUHH!
These environment variables are aptly named: C_INCLUDE_PATH and CPLUS_INCLUDE_PATH. If, however, you want the same for both (you want to use it for both languages) you can just set CPATH.
You’re probably thinking: what else can I do with this marvel... and for that I direct you to the official GCC website.

Xcode 8.2 can't find header files from added search path?

I am having trouble getting Xcode to find opencv header files. In the 'Build Settings' tab I added the recursive path '/usr/local/Cellar/opencv3/include' to 'Header Search Paths' and 'User Header Search Paths' and I have an include of #include "opencv2/core.hpp"
I added the path to both keys because it wasn't working for either one individually so that's just the way I have it right now. The error I get is 'opencv2/core.hpp' file not found. Any suggestions? I'm pretty sure this should be working.
EDIT 1: I also have the key 'Always Search User Paths' set to 'Yes'
My apologies to those who spent time trying to figure out what was wrong. The problem was that I had set the build settings for the UI tests target rather than the application project.
In case others come across the same mistake, This is where the target can be changed:
I don't remember ever changing it in the first place, but apparently I did at some point.
Hopefully this is helpful to the next guy that makes this simple mistake.

Xcode folders and groups confusion

I'm using Xcode (with C++) and my project layout (in the file system, not in Xcode) looks like this:
SubfolderA
-file_A_1, file_A_2
SubfolderB
-file_B_1, file_B_2
Right now I've set up this structure in Xcode via groups. And so, when I want to include file_A_2 in file_B_1, I write #include "file_A_2" in file_B_1.
Is there some way to make an inclusion look like #include "/SubfolderA/file_A_2", so that I can easily see to what directory/subfolder an included file belongs?
One way to see what's going on is to look at the Build Log and expand the line for compiling sourcefile.m. Look at the -I options being passed to the compiler.
If it's not to your liking you can add the source tree in the Build Settings > Header Search Paths to include $(ProjectDir)/srcroot and make it recursive, which saves you from adding each sub-folder individually.
In my experience this has never been necessary, however, as far as I can remember.
As far as the Xcode folders are concerned, if the top-level source folder is added then all sub-folders are automatically added when you add them to the filesystem, saving the hassle of keeping them in sync. You might need to add the top-level folder under the Source Files group for this to work, however.
Surprisingly, in Xcode's Build Settings I've added to User Header Search Paths non-recursive path to my project. This solved my problem.
I ended up here when I was having an issue with XCode while trying to include a header in a group by doing
#include "MyGroup/MyHeader.h"
Turns out the project structure and the file system weren't in sync, so I just had to remove my group from the project, put it in the correct place in Finder, then drag and drop it back into the project in the correct place and it worked for me.
I'm not sure if this is necessary or not, but I also have already set up my app's working directory because I am doing some game programming and need to be able to load in .png and make textures.

XCode 4 Relative #include paths in search?

I'm trying to port over a project I initially wrote in Windows to OS X and am having some difficulty with the header search paths.
I've used user search paths to include by source folder "project/src/core/"
Under core, I have, for example:
"projects/src/core/sys/sys_sdl.h"
which tries to include
"projects/src/core/render/opengl_render.h"
with the directive:
#include "render/opengl_render.h"
I've tried tons of different options, but I can't get seem to get Xcode to find the file unless I change it to "../render/opengl_render.h"
Is there something I'm missing here in the settings to get it to recognize relative paths to the header search paths?
Did you try setting the User Header Search Path to $SRCROOT/..? $SRCROOT is the directory that contains the target's source files, so $SRCROOT/.. should be the directory above that, which I think is what you want.
A related question (How do I print a list of "Build Settings" in Xcode project?) shows a useful command that makes it easy to see all the build settings and the variables they modify:
$ xcodebuild -project myProj.xcodeproj -target "myTarg" -showBuildSettings

Working with Box2D/Cocos2D in an external iOS project

I have followed the instructions as per this article and have been working with Cocos2D without much issues. Recently, I tried including the Box2D headers to try some physics like so:
#import "Box2D.h"
This resulted in a lot of errors where the Box2D.h file could not include the rest of the header files:
../cocos2d-iphone-0.99.5/external/Box2d/Box2D/Box2D.h:34:0 ../cocos2d-iphone-0.99.5/external/Box2d/Box2D/Box2D.h:34:37: error: Box2D/Common/b2Settings.h: No such file or directory
That's the first error and the rest of the 23 are like that, but for the different headers in Box2D.h.
I have already added the projects/targets to the current project as per the instructions in the article, so my project currently looks like this:
Also, I have attempted to remedy this by selecting all .m files in my project and setting the file type to sourcecode.cpp.objcpp but do not think that this is the issue. I am certain that under the User Header Search Paths build setting, the folders where these headers are stored are added. If it weren't, Cocos2D wouldn't be able to compile either.
What am I doing wrong?
I don't know if this is immediately obvious to other programmers, but I fixed this by checking the Always Search User Paths setting in the target settings. Hope it helps someone else.
Another solition for me is removing blank characters from directory names. Forexample if your project folder such as
"user/prj 01"
change it to
"user/prj01".