Getting error from "opencv2.framework".
Just a new project contained "opencv2.framework" not running.
My Steps:
download latest opencv2.framework
add required frameworks
declare .pch file stuff
changed .m file -> .mm
Am I missing something?
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import <Availability.h>
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
#endif /* PrefixHeader_pch */
Line 46 says it all: You have to put opencv.hpp before any Apple's headers. In PrefixHeader.pch move
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
up and before
#import <Availability.h>
Related
I am trying to import #import & it gives me below error:
Declaration of 'objc_property_t' must be imported from module 'ObjectiveC.runtime' before it is required
Here is the code:
#import <Foundation/Foundation.h>
#if TARGET_IPHONE_SIMULATOR
#import <objc/objc-runtime.h>
#else
#import <objc/runtime.h>
#import <objc/message.h>
#endif
Please Note: For Device, it's compiled successfully. It generates an error for Simulator only. This happens since I started using XCode 9. For XCode 8 it was working fine.
It looks like in iOS 11, objc-runtime.h has been removed.
You need to either remove if macro or import , inside it.
I've got a library written in C, where I need to push a call to a method written in Obj-c.
I don't want to modify the original code too much, so I decided to create a "bridge" class to handle the calls between C and ObjC:
DRMBridge.h
#ifndef DRMBridge_h
#define DRMBridge_h
#include "DRMBridgeObjC.h"
void bridge_test();
#endif
DRMBridge.c
#import "DRMBridge.h"
void bridge_test() {
ctest();
}
Above is compiled as C
Now here's my objc code:
DRMBridgeObjC.h
#ifndef DRMBridgeObjC_h
#define DRMBridgeObjC_h
#import <Foundation/Foundation.h>
#interface DRMBridgeObjC : NSObject
+(void) test;
#end
void ctest();
#endif
DRMBridgeObjC.m
#import "DRMBridgeObjC.h"
#implementation DRMBridgeObjC : NSObject
+(void) test {
NSLog(#"OH YEAH!");
}
#end
void ctest() {
[DRMBridgeObjC test];
}
Quite simple.
In the C library I want to call my code from I've added:
#include "DRMBridge.h"
into the .h file and
bridge_test();
in .c file.
Now the best part, when I compile I get:
In file included from /Users/krystian/projects/mdb-reader-lib/reader-Include/ios/MDBReader/Class/DRM/DRMBridge.c:5:
In file included from /Users/krystian/projects/mdb-reader-lib/reader-Include/ios/MDBReader/Class/DRM/DRMBridge.h:8:
In file included from /Users/krystian/projects/mdb-reader-lib/reader-Include/ios/MDBReader/Class/DRM/DRMBridgeObjC.h:12:
In file included from /Applications/Xcode64.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8:
/Applications/Xcode64.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:400:1: error: expected identifier or '('
#class NSString, Protocol;
^
[...]
I went looking, and found this: ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject
However my pch file looks like this:
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
I think the issue I have is that the C compiler tries to compile my ObjC file first, instead of the other way around.
I've tried changing the order of files inside Compile Sources to make sure that my .m file is above .c file, but still no go.
Something else I have found which made me lost:
when I follow this answer: https://stackoverflow.com/a/20461780/487605 and change the library itself to .m, and call [DRMBridgeObjC test] code from there - it works.... Compiles fine, no errors given, works fine.
This implies to me, that there's something screwed up with my DRMBridge, but what?
Thanks
Krystian
You've seen the solution already. Use #ifdef __ OBJC__ in your Objective-C header file so that only the plain C bits are compiled when including the file from C
DRMBridge.h
#ifndef DRMBridge_h
#define DRMBridge_h
#include <CoreFoundation/CoreFoundation.h> //or put in .pch
CF_EXPORT void bridge_test();
#endif
DRMBridge.m
#import "DRMBridge.h"
#import "DRMBridgeObjC.h"
void bridge_test() {
ctest(); //or [DRMBridgeObjC test]; if you like
}
Thats all. And you can include DRMBridge.h in whatever you like: in .c, in .m, in .cpp.
I have two classes that are pretty much identical but one is made for OS X and the other one is made for iOS. Then I have a header file like this:
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
#import "ClassForOSX.h"
#else
#import "ClassForIOS.h"
#endif
The problem is because both classes are included in the project, xcode compiles both and I have a lot of duplicate entries on the errors, because methods have the same name on both classes.
Is there a way to prevent a class from compiling, even if it is included on the project, unless the class is meant for the target?
Yes I know I can include/exclude classes from targets but I am dealing with hundreds of classes in both sides and multiple targets and that would generate a lot of include/exclude operations that will eventually go wrong. I was wondering if there is some solution in code that can just allow a class to compile if the target is right.
Use targets is best for your case. But You can do it in code
note add or remove __MAC_OS_X_VERSION_MIN_REQUIRED at Preprocessor Macros at target->Build Settings
ClassForIOS.h file
#ifndef __MAC_OS_X_VERSION_MIN_REQUIRED
#import <Foundation/Foundation.h>
#interface ClassForIOS : NSObject
// interface
#end
#endif
ClassForIOS.m file
#ifndef __MAC_OS_X_VERSION_MIN_REQUIRED
#import "ClassForIOS.h"
#implementation ClassForIOS
// implementation code
#end
#endif
ClassForOSX.h file
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
#import <Foundation/Foundation.h>
#interface ClassForOSX : NSObject
// interface
#end
#endif
ClassForOSX.m file
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
#import "ClassForOSX.h"
#implementation ClassForOSX
// implementation code
#end
#endif
I want to add AFNetworking without pod and source code to my project. I started by adding source code and then following libraries.
Then I added prefix file
#import <Availability.h>
#if __IPHONE_OS_VERSION_MIN_REQUIRED
#ifndef __IPHONE_6_0
#warning "This project uses features only available in iPhone SDK 6.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#endif
#else
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <AssertMacros.h>
#import <CoreServices/CoreServices.h>
#endif
#endif
And add prefix file to Build Settings -> Apple LLVM 6.1 - Language -> Prefix Header.
After that I built project and I got following errors:
Implicit declaration of function 'SecItemExport' is invalid in C99
Use of undeclared identifier 'kSecFormatUnknown' Use of undeclared
identifier 'kSecItemPemArmour'
Which all are in a file and line. AFSecurity Policy.m, line 31. Which is:
__Require_noErr_Quiet(SecItemExport(key, kSecFormatUnknown, kSecItemPemArmour, NULL, &data), _out);
When I comment this line of code, which is not correct, the rest of project is built completely.
What should I do and why those errors happened?
I found the answer on github.
As mentioned in the release notes for 2.6, if you are installing the library manually you will need to define the following variables in your project's pch:
#ifndef TARGET_OS_IOS
#define TARGET_OS_IOS TARGET_OS_IPHONE
#endif
#ifndef TARGET_OS_WATCH
#define TARGET_OS_WATCH 0
#endif
Github Link.
My solution is to add "TARGET_OS_IOS=1" at Preprocessor Macros -- Build Settings
If I compile it to device or simulator, it works well. But when I do Product --> Archive, it errors:
Login.m
! Semantic Issue
Use of undeclared identifier 'kLogin_URL'
But this works on simulator and device
I am using Xcode version Version 4.6 (4H127). Here is the constant file.
#ifndef MyMobileApp_AllUrls_h
#define MyMobileApp_AllUrls_h
#ifdef QA
#define kLogin_URL #"https://b2bgateway.qa.mycompany.com/authenticate"
#define ktran_URL #"https://b2bgateway.qa.mycompany.com/.../lookup"
#define LOGIN_REQUEST_TIMEOUT 15.0f
#define TRAN_REQ_TIMEOUT 60.0f
#endif
#ifdef PROD
#define kLogin_URL #"https://b2bgateway.mycompany.com/authenticate"
#define ktran_URL #"https://b2bgateway.mycompany.com/.../lookup"
#define LOGIN_REQUEST_TIMEOUT 15.0f
#define TRAN_REQ_TIMEOUT 30.0f
#endif
#endif
The contents of -prefix.pch is
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "AllUrls.h"
#endif
Appreciate your inputs.
Thanks
Make sure your build settings preprocessor macros include PROD under your release configuration.
Per your comment, Just wanted to make sure this is what you did.
#ifdef QA
#define kLogin_URL #"https://b2bgateway.qa.mycompany.com/authenticate"
#define ktran_URL #"https://b2bgateway.qa.mycompany.com/.../lookup"
#define LOGIN_REQUEST_TIMEOUT 15.0f
#define TRAN_REQ_TIMEOUT 60.0f
#else
#define kLogin_URL #"https://b2bgateway.mycompany.com/authenticate"
#define ktran_URL #"https://b2bgateway.mycompany.com/.../lookup"
#define LOGIN_REQUEST_TIMEOUT 15.0f
#define TRAN_REQ_TIMEOUT 30.0f
#endif