0

I'm trying to compile a C++ file on a Mac that uses opencv2.

I downloaded opencv, found an opencv2 folder in it, and copied it into the folder where main.cpp (the program I'm trying to run is).

The folder structure is:

  • main.cpp
  • BRIEF.h
  • opencv2
    • core.hpp
    • core
      • cvdef.h

My current command (after reading this and this) is g++ -I/opencv2/core.hpp main.cpp, run from within the same folder main.cpp is in.

main.cpp has #include "BRIEF.h" which works fine.

BRIEF.h has #include "opencv2/core.hpp" which works fine.

core.hpp has #include "opencv2/core/cvdef.h" which fails saying the file was not found.

How do I use G++ such that the file can be found?

Pro Q
  • 4,391
  • 4
  • 43
  • 92

1 Answers1

3

As you said, you are only including this file/opencv2/core.hpp so it is normal that the compiler fails finding the other files.

In your code you are including your files starting from your project root directory, so you have to include the project root directory for the compiler to find these files:

g++ -I$(PROJECT_DIR) $(PROJECT_DIR)/main.cpp 

or if you run g++ from the root directory, you can use ., which will expand into the current path (your project root directory):

g++ -I. main.cpp 
Blasco
  • 1,607
  • 16
  • 30