Announcing the new Objective Sharpie

abockabock USXamarin Team, Insider Xamurai
edited July 2016 in Xamarin.iOS

I am pleased to announce a new public release of Objective Sharpie, the tool we use at Xamarin to produce C# bindings of Objective-C libraries for Mac and iOS!

Since the last public release, Objective Sharpie has matured very nicely. We have been evolving and using the tool internally at Xamarin for over a year. This year, APIs introduced in iOS 8 and Mac OS X 10.10 were bootstrapped entirely with Objective Sharpie, which was a huge milestone.

We have scrapped the GUI wizard that previously sat on top of the core in favor of a command line tool. Objective Sharpie is a very advanced tool that requires advanced knowledge of Objective-C and C, how to use the clang compiler on the command line, and generally how native libraries are put together. Because of this high bar, we felt that having a GUI wizard set the wrong expectations.

Objective Sharpie comes with one major rule for proper usage: you must absolutely pass it the correct clang compiler command line arguments in order to ensure proper parsing. This is because the Objective Sharpie parsing phase is simply a tool implemented against the clang libtooling API.

This means that Objective Sharpie has the full power of clang (the C/Objective-C/C++ compiler that actually compiles the native library you would bind) and all of its internal knowledge of the header files for binding. Instead of translating the AST to object code, Objective Sharpie translates the AST to a C# binding "scaffold" suitable for input to the bmac and btouch Xamarin binding tools. So if Objective Sharpie errors out during parsing, it means that clang errored out during its parsing phase trying to construct the AST, and you need to figure out why.

Unfortunately that's not always an easy task. My quick advice is to always build the native library you are trying to bind, and then build a simple native program against that native library. The compiler flags you use to build the simple native program are what (in some form) you need to pass to Objective Sharpie. Often you can simply run xcodebuild and discern what's required. However, this is a manual process, and one that does require a bit of familiarity with compiling native code on the command line.

In the coming weeks and months we will be exploring ways of improving how we can discern these command line arguments for you, but no two projects are alike. We have some good ideas that should help with a large number of public open source projects and some proprietary projects.

I've spent the last few weeks polishing Objective Sharpie up from its life over the last year as a strictly-internal tool to something that public users can consume, and I hope it is truly useful.

While Objective Sharpie is not a supported Xamarin product we are eager to collect your feedback on it! To help us collect actionable information about areas we need to improve, Objective Sharpie by default submits usage data back to Xamarin for analysis (using Xamarin Insights of course). While you can opt-out of this process, we encourage you not to do so in order to help evolve the tool. Note that we do not submit any source code or other files - just the command line arguments that you pass to Objective Sharpie and some environment and build information.

We have updated the documentation on Objective Sharpie and will continue to do so as the tool evolves. We are committed to making more frequent public releases as well now that we are satisfied with the maturity of the tool internally.


Obligatory Screenshot

You can still take screenshots of command line tools!


  • DanArdeleanDanArdelean ITInsider, Beta, University ✭✭

    Thank you

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭


  • MarkRadacz.7953MarkRadacz.7953 USInsider, University, Developer Group Leader ✭✭

    Well done.. thank you!

  • trinnguyentrinnguyen VNMember ✭✭

    Great (y). Thank you !!!

  • @abock‌ I see you're sample is POP.h, you didn't happen to finish that binding did you :) I know alot of Xamarin.iOS developers that would be very happy to have one

  • ChuckPinkertSqorChuckPinkertSqor USMember
    edited January 2015

    And more importantly, THANK YOU! Haven't tried it just yet, but obj-sharpie needed the love

  • songliuchensongliuchen CNMember

    Great ! if it can operator by window form like preview version would be more better

  • JonathanDickJonathanDick CAXamarin Team, Developer Group Leader Xamurai

    @ChuckPinkertSqor you can get the Facebook Pop component on the component store :)

  • Didn't know that was there, Awesome thanks @Redth , appreciate it

  • pratibhapratibha USMember

    While generating APIDefinition using Objective Sharpie its throwing an error

    Code in Header file:
    struct Alert : public Message {
    virtual void clear() = 0;

    - /Users/Prajwal/Desktop/iOS/sdk/NotifyCall.framework/Versions/A/Headers/ShowNotify_basetypes.h:442:2: error: unknown type name 'virtual'
    virtual void clear() = 0;

    Please provide solution how to overcome this error

  • abockabock USXamarin Team, Insider Xamurai
    edited April 2015

    @pratibha You are trying to parse C++ but have not told the underlying Clang compiler that the input is C++. Pass -xc++ to Clang. Note however, that Objective Sharpie does not actually bind C++ constructs - only Objective-C.

    Something like: sharpie bind header.h -c -xc++

    Remember that any arguments passed after the -c or -clang are passed directly to Clang.

  • juniorlielhjuniorlielh CGMember

    je n'ai pas compris

  • ganesh.pganesh.p USMember ✭✭

    Does Sharpie tool supports binding for Native C library? When I use this with a 3rd party library, it generates only EnumsAndStructs.cs file, does not generate ApiDefinition.cs file. Does this mean, I cannot create binding project for this library, I have to go for Linking Native Libraries approach to access it from Xamarin.

  • PierPier MXMember

    Is there something similar for Android / Java?

  • SureshValle480SureshValle480 USMember ✭✭
    edited January 2017

    Hi @AaronBockover

    I am trying to creating xamarin.iOS bindings from .framework file using Objective Sharpie (version 3.3) but unable to generating ApiDefinition.cs. file, its only generating StructsAndEnums.cs

    below are the steps I followed to generate ApiDefinition.cs. and StructsAndEnums.cs files, from the attached .framework file.

    Tecordeons-iMac-2:~ tecordeon$ sharpie xcode -sdks
    sdk: appletvos10.1 arch: arm64
    sdk: iphoneos10.2 arch: arm64 armv7
    sdk: macosx10.12 arch: x86_64 i386
    Tecordeons-iMac-2:~ tecordeon$ sharpie bind -output FirebaseCrashReport -namespace FirebaseCrashReport -sdk iphoneos10.2 /Users/tecordeon/Downloads/Firebase/Crash/FirebaseCrash.framework/Headers/FIRCrashLog.h
    Parsing 1 header files...

    [write] StructsAndEnums.cs

    Binding Analysis:
    Automated binding is complete, but there are a few APIs which have been flagged with [Verify] attributes.
    While the entire binding should be audited for best API design practices, look more closely at APIs with
    the following Verify attribute hints:

    PlatformInvoke (8 instances):
    In general P/Invoke bindings are not as correct or complete as Objective-C bindings (at least currently).
    You may need to fix up the library name (it defaults to '__Internal') and return/parameter types
    manually to conform to C calling conventionsfor the target platform. You may find you don't even want to
    expose the C API in your binding, but if you do, you'll probably also want to relocate the definition to
    a more appropriate class and expose a stronger type-safe wrapper. For P/Invoke guidance, see http://www.

    Once you have verified a Verify attribute, you should remove it from the binding source code. The presence
    of Verify attributes intentionally cause build failures.

    For more information about the Verify attribute hints above, consult the Objective Sharpie documentation
    by running 'sharpie docs' or visiting the following URL:

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


    Please let me know if i missed any thing, which causes ApiDefinition.cs file not generating.

Sign In or Register to comment.