Search code examples
externallivecodexcode10

Building a C/C++ external for LiveCode 9.01 with Xcode 10


I've taken over maintenance for an old LiveCode application which uses a custom external library written in C. The application is no longer working with recent platform and I'm reasonably sure that complications with the external are to blame. I'm new to LiveCode and don't use Xcode frequently.

I decided to build a simple external using the most recent LiveCode documentation I could find (from Nov 2006):

http://newsletters.livecode.com/november/issue13/newsletter5.php

As i386 architectures are no longer supported, I've removed the PowerPC-32 and x86-32 from all Xcode project build target configurations, and i386 from the list of valid architectures. These changes allow the project to build in Xcode properly.

Xcode 10 doesn't seem to have the same interface referenced by the old article for building in release mode. To perform the initial step of building in Release configuration, I have run Product > Archive from the menu.

When I then 'Run' the project, making sure the the build configuration from the 'manage schemes' interface is 'Debug', the LiveCode test stack rnaHelloStack.rev doesn't open automatically. I am able to make that happen by defining the LiveCode Indy 9.0.1.app executable for the scheme and EITHER:

1) Defining the working directory in the scheme options AND passing the rnaHelloStack.rev as an argument. 2) Choosing the Launch option for the scheme to 'Wait for executable to be launched' and opening the rnaHelloTest.rev file directly from the Finder after running the project.

In all cases, when the rnaHelloTest.rev is opened in LiveCode and I add the button handler script, the code halts execution at the call to the external function.

I have tinkered with the LiveCode code and variables. My best guess is that the external is not properly loaded into the stack. I've scoured for more recent documentation but have found nothing except this old forum post trying a similar thing:

https://forums.livecode.com/viewtopic.php?f=17&t=11295&sid=380a6fe4b12111f767fc863262a3acf9

How can I assure a simple external like this from the documentation is available to a LiveCode stack via the updated LiveCode 9.0.1 IDE and Xcode 10?


Solution

  • As mentioned by @jjsjjs using Xcode 9.4 for now will be simpler due to LiveCode itself still supporting i386 builds but Xcode no longer doing so. You probably want to build a universal binary for i386 & x86_64 for the moment unless you know for sure the app will be built as x86_64 only. If only building for x86_64 ensure LiveCode is not opening in 32 bit mode via the checkbox on the Get Info palette. FWIW we use Xcode 9.4 and symlink in macOS 10.9 sdk and build LiveCode against that.

    The external documentation is very out of date. We are steering people to use the FFI features in LiveCode Builder these days, however, if you just want to get the external working again rather than start from scratch I suggest cloning one of my open source externals and basing your external on that. Either mergJSON or mergMarkdown. Note that both use submodules so ensure to clone recursively.

    Neither of those externals have a test target where they launch in the IDE. You copy the built external into your plugins folder following these instructions then launch LiveCode. When developing a new external I usually add a build phase that does those steps via a script to save time.

    There are also some examples in our engine repo however because we use gyp to generate our project files they may not be as helpful.