Sharpie can't parse my header (.h) files because it finds lots of errors in the iOS SDK.

hkprojhkproj ITMember ✭✭

Hello

I am trying to bind an Objective-C library and I have successfully generated the binaries. However, when using Objective Sharpie, I get a list of errors that seem to be originating inside the iOS SDK. I launch the following command:
sharpie bind --output RealtimeSharp --namespace Realtime --sdk iphoneos9.0 ./Realtime/OrtcClient.h
and I get the following output:

Parsing Native Code...
In file included from /Users/Umar/Documents/Projects/Realtime/Realtime/OrtcClient.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:19:21: error: 
      expected a type
- (id)copyWithZone:(nullable NSZone *)zone;
                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:25:28: error: 
      expected a type
- (id)mutableCopyWithZone:(nullable NSZone *)zone;
                           ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:32:4: error: 
      expected a type
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder; // NS_DESIGNATED_INITIALIZER
   ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:53:4: error: 
      expected a type
- (nullable id)replacementObjectForCoder:(NSCoder *)aCoder;
   ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:54:4: error: 
      expected a type
- (nullable id)awakeAfterUsingCoder:(NSCoder *)aDecoder NS_REPLACES_RECEIVER;
   ^
In file included from /Users/Umar/Documents/Projects/Realtime/Realtime/OrtcClient.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:6:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:7:15: error: 
      expected ';' after @class
@class NSArray<ObjectType>;
              ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:7:16: error: 
      cannot find protocol declaration for 'ObjectType'
@class NSArray<ObjectType>;
               ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:34:25: error: 
      cannot find protocol declaration for 'ObjectType'
@interface NSEnumerator<ObjectType> : NSObject <NSFastEnumeration>
                        ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:34:37: error: 
      expected identifier or '('
@interface NSEnumerator<ObjectType> : NSObject <NSFastEnumeration>
                                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:36:4: error: 
      expected a type
- (nullable ObjectType)nextObject;
   ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:25: error: 
      cannot find protocol declaration for 'ObjectType'
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
                        ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:1: error: 
      duplicate interface definition for class 'NSEnumerator'
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:34:12: note: 
      previous definition is here
@interface NSEnumerator<ObjectType> : NSObject <NSFastEnumeration>
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:37: error: 
      method type specifier must start with '-' or '+'
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
                                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:40:38: error: 
      expected a type
@interface NSEnumerator<ObjectType> (NSExtendedEnumerator)
                                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:1: error: 
      expected selector for Objective-C method
@property (readonly, copy) NSArray<ObjectType> *allObjects;
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:28: error: 
      unknown type name 'NSArray'
@property (readonly, copy) NSArray<ObjectType> *allObjects;
                           ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:35: error: 
      expected member name or ';' after declaration specifiers
@property (readonly, copy) NSArray<ObjectType> *allObjects;
                           ~~~~~~~^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:1: error: 
      property requires fields to be named
@property (readonly, copy) NSArray<ObjectType> *allObjects;
^                          ~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSEnumerator.h:42:35: error: 
      expected ';' at end of declaration list
@property (readonly, copy) NSArray<ObjectType> *allObjects;
                                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Error while processing /Users/Umar/Documents/Projects/Realtime/Realtime/OrtcClient.h.

Submitting usage data to Xamarin...
  Submitted - thank you for helping to improve Objective Sharpie!

Done. Exiting with error code 1.
error: Clang failed to parse input and exited with code 1

My list of SDKs (sharpie xcode -sdks):

sdk: iphoneos9.0          arch: arm64   armv7
sdk: macosx10.11          arch: x86_64  i386
sdk: watchos2.0           arch: 
sdk: watchsimulator2.0    arch: 

My Objective Sharpie version is (sharpie --version):
2.1.6p 6e2f8ea 6e2f8ea5ac2f544c58938555a06ef21a4ecb032a 2015-03-17 17:39:55
And my Xamarin Studio's version is 5.9.7 (build 9).

Thank you,
Umar

Best Answer

Answers

  • BrianWheelerBrianWheeler USMember

    I'm getting the same issue. Any word on this?

  • abockabock USXamarin Team, Insider Xamurai

    We will be releasing a new version of Objective Sharpie early next week that has Xcode 7 and Objective-C generics support.

  • JohnHaitasJohnHaitas USMember

    Experiencing the same issue here.

    Looks like it is due to new Objective-C features like the nullable attribute and generics.

    Please help.

  • _JamesMundy_JamesMundy GBMember ✭✭
    edited December 2015

    I have the same issue also, does anyone have a solution for this?
    Seems 3.0 hasn't made any difference.

  • dikogadikoga USMember ✭✭

    Guys, I am running into an issue quite similar..

        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:435:1: error: 
              expected identifier or '('
        @class NSString, Protocol;
        ^
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:437:19: error: 
              unknown type name 'NSString'
        FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
                          ^
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:438:44: error: 
              unknown type name 'NSString'
        FOUNDATION_EXPORT SEL NSSelectorFromString(NSString *aSelectorName);
    

    This is the command: sharpie bind -sdk iphoneos9.1 WePay.framework/Headers/WePay.h -scope WePay.framework/Headers -c -F

    Sharpie Version: 3.0.8p 021aa16 021aa16f1ce05205c16afd18a6f63bf79e758386 2015-10-05 21:07:23

    sharpie xcode -sdks:
    sdk: appletvos9.0 arch: arm64
    sdk: iphoneos9.1 arch: arm64 armv7
    sdk: macosx10.11 arch: x86_64 i386
    sdk: watchos2.0 arch: armv7

    Any ideias?

  • abockabock USXamarin Team, Insider Xamurai

    3.0 definitely has nullable and ObjC generics support, so this thread is likely now just being bolted on to for unrelated reasons.

    @dikoga in your case it looks like you are trying to directly parse a framework header file but aren't passing the fact that the compiler should use the Objective-C parser. You'll want to pass -xobjective-c after the -c argument to help the compiler out.

    Even better, you might also try telling Objective Sharpie to parse the whole framework so it can deduce some more things for you, so you don't have to specify everything manually.

    Assuming you're using WePay from GitHub, I produced the binding scaffolding like this:

    git clone https://github.com/wepay/wepay-ios
    cd wepay-ios
    xcodebuild
    sharpie bind -sdk iphoneos9.1 -framework build/Release-iphoneos/WePay.framework
    

    You now have an ApiDefinition.cs file that contains the binding scaffolding that you may integrate in an iOS binding project.

    This exact scenario is covered in Objective Sharpie documentation.

  • dikogadikoga USMember ✭✭

    @abock

    First thanks for the answer!

    And I've tried that way, but using the zip file which contains the framework (https://github.com/wepay/wepay-ios/releases/tag/v3.0.0). In this case, sharpie just generates the constants.

    What is the difference? Cause following your tips, it generates the whole binding!! :)

Sign In or Register to comment.