2

I'm trying to bridge OpenCV c++ to my Swift application.

And I'm getting this error:

Users/admin/Desktop/MDAcne/MDAcne/MDAcne-Bridging-Header.h:14:9: note: in file included from /Users/admin/Desktop/MDAcne/MDAcne/MDAcne-Bridging-Header.h:14:
#import "cvVideoWrapper.h"
        ^
/Users/admin/Desktop/MDAcne/MDAcne/cvVideoWrapper.h:13:9: note: in file included from /Users/admin/Desktop/MDAcne/MDAcne/cvVideoWrapper.h:13:
#import "algo.hpp"
        ^
/Users/admin/Desktop/MDAcne/MDAcne/algo.hpp:11:10: note: in file included from /Users/admin/Desktop/MDAcne/MDAcne/algo.hpp:11:
#include <opencv2/video/background_segm.hpp>
         ^
/Users/admin/Desktop/MDAcne/Pods/OpenCV/opencv2.framework/Headers/video/background_segm.hpp:47:10: error: 'list' file not found
#include <list>
         ^
<unknown>:0: error: failed to import bridging header '/Users/admin/Desktop/MDAcne/MDAcne/MDAcne-Bridging-Header.h'

cvVideoWrapper.h and cvVideoWrapper.mm connect between the bridging header to algo.hpp which is the c++ file. algo.hpp includes those libraries:

#include <opencv2/video/background_segm.hpp>
#include <opencv2/video/tracking.hpp>

which contains #include <list> which is a C file that is causing the problem as I understand.

I saw in another question that this can be fixed by changing the .m files to .mm files. I've done this and I still get this error. In addition seems that in my case it's happening in the cvVideoWrapper.h file.

How can this be fixed?

Community
  • 1
  • 1
Oded Harth
  • 4,367
  • 9
  • 35
  • 62

2 Answers2

1

#include <list>

is a C++ header, so you need to build with the obj-c++ compiler. Depending on your build environment, using the .mm suffix is often sufficient to invoke the obj-c++ compiler.

How are you building this? And what file is including

/Users/admin/Desktop/MDAcne/MDAcne/MDAcne-Bridging-Header.h

That file also needs a .mm suffix...

Edit: as discussed below, the user was trying to include obj-c++ directly from swift. This will not work:

Can I mix Swift with C++? Like the Objective - C .mm files

Use an obj-c++ wrapper and don't include the c++ headers from swift; nothing on the direct include chain can reference c++. So, move the:

#include <list>

to the cvVideoWrapper.mm file. You may have to re-architect things a bit.

Community
  • 1
  • 1
Joey Yandle
  • 141
  • 4
0

In my case, the problem was in the PrefixHeader file. After removing this import my problem is solved.

enter image description here

Ozgur Sahin
  • 1,305
  • 16
  • 24