Christian
Christian

Reputation: 1041

g++ compilation using 'include' statement with non-relative paths (C++)

I am trying to compile a c++ code with a third party library using g++ as a compiler. My main.cpp needs to include the header file core.hpp while the core.hpp needs to include cvdef.h whereas cvdef.h need to include interface.h.

The paths for these three headers in the include statements are as follows:

#include "opencv2/core.hpp"
#include "opencv2/core/cvdef.h"
#include "opencv2/core/hal/interface.h"

See file structure in image below.

When I compile my main.cpp it finds the core.hpp. The core.hpp, however, cannot seems to find cvdef.h as it is looking within the 'core'-folder for the 'opencv2'-folder (which is a level below). Without changing the paths in the include statement, how would I go about this?

My current compile statement using g++ under Windows is:

g++ main.cpp -o main

enter image description here

Upvotes: 1

Views: 443

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409482

It seems that OpenCV2 wants to look for the header files in standard locations.

You can add to the list of standard locations by using the -I (upper-case i) option, specifying the path to add.

In your case you should be able to do it with

g++ main.cpp -o main -Iopencv2/core

Upvotes: 2

Related Questions