Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange unmatched curly brace in OpenCV

I am using the version of OpenCV for iPhone, and I have encountered a somewhat strange error. In using the stitcher, some of the imported headers are now complaining about an unmatched '{' on this line:

enum { NO, FEATHER, MULTI_BAND };

NO is a macro from objc.h which is defined as

#define NO              __objc_no

And the compiler is expecting a '}' to match the opening of the enum, even though there is one just a little later on. What is happening?

like image 342
Jumhyn Avatar asked Nov 30 '22 22:11

Jumhyn


1 Answers

I have been having the same problem for a long time and I have just now discovered a workaround. As you stated correctly it is a problem with definition of the NO-makro in UIKit. What you need to do is go to your .pch-file and replace

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

with

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#import <opencv2/stitching/detail/blenders.hpp>
#import <opencv2/stitching/detail/exposure_compensate.hpp>
#endif

So your resulting .pch should look something like this:

//
// Prefix header for all source files of the 'Project' target in the 'Project' project
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#import <opencv2/stitching/detail/blenders.hpp>
#import <opencv2/stitching/detail/exposure_compensate.hpp>
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif

This way the NO-enums in blenders.hpp and exposure_compensate.hpp are defined before the NO-makro in UIKit.

like image 71
Chris Avatar answered Dec 03 '22 12:12

Chris