0

I am a beginner at c++ and I'm having this problem with nested include files. The code is too big to put here, but this is the part that I'm getting the error:

cvblob.h

#ifdef SWIG
%module cvblob
%{
#include "cvblob.h"
%}
#endif

#ifndef CVBLOB_H
#define CVBLOB_H

#include <iostream>
#include <map>
#include <list>
#include <vector>
#include <limits>

#include <opencv2/opencv.hpp>

#ifndef __CV_BEGIN__
#define __CV_BEGIN__ __BEGIN__
#endif
#ifndef __CV_END__
#define __CV_END__ __END__
#endif

#ifdef __cplusplus
extern "C" {
#endif

...

At line 4 in the above code (#iclude "cvblob.h"), the error happens:

[package_tracking/cvblob/cvblob.h:26]: (error) #include nested too deeply

The guards are already used, but the error doesn't go away. Sorry that I am not able to put the entire code. If it is not possible to figure it out without the entire code, please answer these questions:

  • Should I put the guards (#ifndef CVBLOB_H) before the first line?
  • Is it necessary to put the guards in all the header files?

Thank you! I appreciate any suggestions.

Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58
  • Is this code you wrote or is it part of some package? – Max Langhof Aug 16 '19 at 15:09
  • I dont remember how to do it correctly for swig, but the `#ifdef` / `#endif`s are not balanced and it looks fishy that you include `cvblob.h` in itself. – 463035818_is_not_an_ai Aug 16 '19 at 15:09
  • @MaxLanghof it's part of a package. I am just using it. – Hadi GhahremanNezhad Aug 16 '19 at 15:10
  • @formerlyknownas_463035818 The code presumably continues after the given snippet (as indicated by the unmatched `extern "C" {`). – Max Langhof Aug 16 '19 at 15:10
  • @MaxLanghof yes, it continues. This is the top part of the header file. – Hadi GhahremanNezhad Aug 16 '19 at 15:11
  • 1
    In that case this is some issue related to SWIG integration in OpenCV, which I know absolutely nothing about. The code is not valid C++ (if `SWIG` is defined, which it appears to be) due to the `%` stuff at the top, so I've added the SWIG tag and hope those folks can help you! – Max Langhof Aug 16 '19 at 15:12
  • 2
    Code with `%module` stuff should only appear in `.i` files and then the SWIG guard does not make sense. Provide a full example, which demonstrates the error – Jens Munk Aug 17 '19 at 18:10

0 Answers0