Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thefuntastic
Last active January 19, 2020 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefuntastic/5b57c0ab540d6738f3ee2e518dd46652 to your computer and use it in GitHub Desktop.
Save thefuntastic/5b57c0ab540d6738f3ee2e518dd46652 to your computer and use it in GitHub Desktop.
LibPDIntergration iOS static library build instructions
# LibPd Binaries
LibPDIntegration relies on 64bit multi-user Libpd (https://github.com/libpd/libpd), which we now have to build ourselves. For an inexperienced user this can be black magic! It is also confusing because the libpd notes on iOS (https://github.com/libpd/pd-for-ios) tend to point towards using a wrapper for a native AU (Audio Unit) plugin. However as we're using Unity's native sound layer we don't need to worry about this.
It is also possible to embed a xcode project as a subproject of parent xcode Project. Eg the libpd xcode project would live under the Unity xcode project. The advantage of this scheme is that you will always build a valid libpd version for your Unity Project. However this is less portable as the Unity xcode project gets regenerated and one would have to set it up again each time.
Instead we choose to build a static library `*.a` file which is a native iOS plugin (aka a `*.dll`) and can be embedded inside Unity. (As `libpd/libpd.xcodeproj` already exists the following is only provided for further reading: https://www.raywenderlich.com/2658-creating-a-static-library-in-ios-tutorial)
1. Clone the main LibPD project https://github.com/libpd/libpd.git (`Users/peter/Resources/libpd/libpd`)
2. Open the xCode project included in the repo `libpd/libpd.xcodeproj`
3. Select the build target `libpd-ios-multi` > `iPhone 8` (It seems you must select a device, as generic iOS device fails. Can also select a device plugged into the mac. Eg `Peter's Ipad`)
4. When archiving (a step for distributing to the AppStore) one might run into the following error: `Bitcode bundle could not be generated because '/Users/peter/Projects/cadence_64/xcode/Cadence64/Libraries/Plugins/libpd-ios-multi.a(z_libpd.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture arm64`.
To get around this (https://medium.com/@heitorburger/static-libraries-frameworks-and-bitcode-6d8f784478a9):
- In the project navigator (left hand window, select the folder icon at the top), select libpd.
- Select `libpd-ios-multi` in the middle pane
- `Build Settings` search for `Apple {Clang|LLVM} - Custom Compiler Flags` > `Other C Flags`
- Add `-fembed-bitcode` to both release and debug options
- NB: this deviates for the linked article - we need to set debug as `-fembed-bitcode` instead of `-fembed-bitcode-marker` because "Running" the project will only produce a debug target.
4. `Product > Build`
5. In the project navigator (left hand window, select the folder icon at the top), twirl down the libpd project. Under Products, select the image `libpd-ios-multi.a`
6. Try `Right Click > Show in Finder`. If that doesn't work, on the right hand panel under `Identity and Type` it should show the library and it's compiled folder path which you can manually find in the finder. (This ends up in a temporary Xcode folder called `Derived Data`)
7. Copy `libpd-ios-multi.a` to the Unity project under `Assets/Plugins/` and make sure include platforms is set to `iOS`, and set CPU architechture to `arm64`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment