3

I'm trying to build a Swift framework that includes C++ and OpenCV Framework for iOS

As far as I understand we can't have a bridging header in framework, we have to deal with umbrella header.

My issue is that XCode is not processing C++ file as C++, with that kind of compiler error :
Unknown type name 'class'; did you mean 'Class'? It also cannot find <iostream>

I currently have my umbrella that is including a objc wrapper for my C++ files.
What is the right way to do it ?

Below my framework umbrella header

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#else
    #ifndef FOUNDATION_EXPORT
        #if defined(__cplusplus)
            #include <iostream>
            #define FOUNDATION_EXPORT extern "C"
        #else
            #define FOUNDATION_EXPORT extern
        #endif
    #endif
#endif

#import "AGImageDescriptor.h"
#import "AGKitLib.h"
#import "Detector.h"
#import "Observable.h"
#import "Shooter.h"
#import "DocumentDetectedState.hpp"
#import "DocumentMatchState.hpp"
#import "GoodPerspectiveState.hpp"
#import "GoodPositionState.hpp"
#import "InactiveState.h"
#import "ReadyState.hpp"
#import "StartState.h"
#import "State.h"
#import "States.h"
#import "TextDetectedState.hpp"
#import "Tools.hpp"
#import "OpenCVWrapper.h"
#import "UIImage+OpenCV.h"

FOUNDATION_EXPORT double AGKitScanVersionNumber;
FOUNDATION_EXPORT const unsigned char AGKitScanVersionString[];

I am really not an C++ expert nor a C expert so I am probably missing something here.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Akhu
  • 207
  • 2
  • 13

1 Answers1

2

The errors your are getting indicate that your umbrella header possibly includes C++ code, directly or indirectly. In fact, I see a lot of .hpp files, which are probably C++ headers. With Swift code being present in the framework, you cannot do that. All C++ code must be confined to the Objective-C++ wrapper's implementation files (.mm extension, not .m used for Objective-C files). Objective-C++ (.mm) files can used a mixture of C++ and Objective-C code and include the necessary C++ headers.

Here are some questions/answers that might help: Unknown type name 'class'; did you mean 'Class'? and Video processing with OpenCV in IOS Swift project

Anatoli P
  • 4,791
  • 1
  • 18
  • 22
  • Sorry for the late reply. That helped me a lot :) Indeed every C++ file should be declared inside the umbrella header. Thanks ! – Akhu Nov 14 '17 at 15:56
  • @Akhu can you update your question with the final umbrella header details. I am also trying to do the same thing but have never heard of an umbrella header so have no idea where this even needs to go. Thanks – Duncan Groenewald Jun 07 '18 at 04:23