Build an Objective-C bindings library with Objective Sharpie - IOS451

Exercise 3: Initiate the binding process on an existing Xcode framework project (IOS451)

The primary goal of this lab is to bind an existing Xcode Framework using Objective Sharpie.

If you haven't already, you will need to download Objective Sharpie. Additionally, you will need to complete this exercise on a Mac running macOS 10.10 or newer for compatiblity with Objective Sharpie.

Objective Sharpie has a minimum requirement of macOS 10.10 or newer.

Clone target library

To start, you are going to clone the Pop animation library again.

  1. Create a folder for you exercise content.
  2. Open Terminal and navigate to your exercise folder.
  3. Type the following command to clone the Pop library from GitHub.
git clone https://github.com/facebook/pop.git

Build project with Xcode

Now, we'll build the Pop project using Xcode.

  1. Navigate your command-prompt to the newly Git-created pop folder.
  2. Run the following command.
xcodebuild -sdk iphoneos11.4 -arch arm64
You may need to adjust the -sdk parameter to match an installed SDK version on your PC. If you are unsure what SDKs you have installed, you can list available Xcode SDKs with sharpie xcode -sdks.

Process project into an API definition

Now, we can run an Objective Sharpie command to process the library into the API definition files.

  1. Run the following command in the pop folder. It is broken into multiple lines for easier legibility; make sure to copy the whole command.
sharpie bind -output XamarinFacebookPop -namespace FacebookPOP \
-sdk iphoneos11.4 -scope build/Release-iphoneos/include/pop/ \
build/Release-iphoneos/include/pop/POP.h

There are a few aspects that needs to be specified for the binding:

You may need to adjust the -sdk parameter to match an installed SDK version on your PC. If you are unsure what SDKs you have installed, you can list available Xcode SDKs with sharpie xcode -sdks.

You will see an error in the Objective Sharpie output like this, suggesting an include from POP.h wasn't found. The #import statements are defined using angle-brackets which define global includes. Using global includes requires relative or absolute paths passed to the compiler. Objective Sharpie however will not find the files, as specified, since the path is interpreted absolutely. Change the #import statement to make use quotation marks.

'Parsing 1 header files...
/.../pop/build/Release-iphoneos/include/pop/POP.h:13:9: fatal error: 'pop/POPDefines.h' file not found
#import <pop/POPDefines.h>
        ^~~~~~~~~~~~~~~~~~

Binding...
1 error generated.
Error while processing /.../pop/build/Release-iphoneos/include/pop/POP.h.'
  1. Open the POP.h file in the pop/build/Release-iphoneos/include/pop/ folder and update all the #import statements.

For example, for this import statement:

#import <pop/POPDefines.h>

You would update it to look like this (using quotation marks and omitting the pop/ sub-folder.):

#import "POPDefines.h"
Do not change any of the external libraries used. For example, all imports which do not include the prefix pop, such as #import <Foundation/NSException.h>.
  1. With these updates in place, re-run the sharpie command.

Next, you will see that each of the referenced files from POP.h also reference other imports that need to be updated.

For example, this is the error reported for the POPAnimatableProperty.h file.

'Parsing 1 header files...
In file included from /.../pop/build/Release-iphoneos/include/pop/POP.h:15:
/.../pop/build/Release-iphoneos/include/pop/POPAnimatableProperty.h:14:9: fatal error: 'pop/POPDefines.h' file not found
#import <pop/POPDefines.h>
        ^~~~~~~~~~~~~~~~~~

Binding...
  [write] ApiDefinitions.cs
  [write] StructsAndEnums.cs'

...
  1. Update the #import <pop/{file}.h> references in the remaining Pop header files, switching the statements to use quotation marks and omit the pop/ sub-folder.

If you miss any files, Objective Sharpie will report a similar error for any files you have remaning to update.

  1. With these manual edits in place, run the sharpie command again.

Inspect the current folder to make sure Objective Sharpie created a folder called XamarinFacebookPop containing two files.


Exercise summary

In this exercise you saw how to initiate the binding process on an existing Xcode Framework project using Objective Sharpie.

Go Back