KudanCV won't compile with with Swift > 'memory' file not found


#1

I am trying to add KudanCV to an iOS Swift application, but when I try to build I get the following error.

‘memory’ file not found KudanCV.h
‘Failed to import bridging header’

The error occurs on line 12 of KudanCV.h

#include <memory>

My Swift Bridging header only includes the import line

#import "KudanCV.h"

It seems like there is a need for more C++ support libraries, but I’m not sure how to configure my Xcode project for that, or if its possible.


#2

I’ve realised/discovered that the KudanCV header file, because it imports C++ libraries is not compatible with Swift.

Swift C and Obj-C compatibility does not extend to C++, and in bridging headers any .h that depends on further C++ libraries such as and cannot be imported. Any headers exposed to Swift must not import C++ dependencies.

In practice the fix for this (assuming that the KudanCV framework will continue to expose C++ types to iOS) must be to wrap KudanCV in Objective-C and only expose these wrapped API’s to Swift indirectly.

This SO thread has some context http://stackoverflow.com/questions/24042774/can-i-mix-swift-with-c-like-the-objective-c-mm-files


#3

I’ve found this tutorial that helps explain how to link C++ with Swift. I hope this helps

http://www.demusoft.com/2016/01/consuming-a-c-library-from-swift/


#4

Hello everyone, I want to ask should I learn Swift or Objective-C now, I Read this https://www.cleveroad.com/blog/swift-vs-objective-c--what-is-the-best-language-for-ios-development-
and now I am confused!
Can you help me?