No description, website, or topics provided.
Objective-C C Swift C++
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
built
files
src
.gitignore
README.md

README.md

Frameworks and Libraries

This write-up is an attempt to organize information about using Frameworks and Libraries for macOS, all in one place.

It's a challenge to come up with a scheme for organizing things. Some questions that arise:

  • in what language is the helper function, library or framework written?
  • is it from macOS or from me, the user?
  • where is the library or framework currently located?
  • in what language is the caller written?
  • are we compiling on the command line, calling from a Cocoa app or what?

Roughly speaking, we'll try to organize things that way, from the outside in.

An outline of what we'll look at is

  • classic C libraries, both static and dynamic
  • C libraries wrapped into Cocoa frameworks
  • calling libraries from Objective-C
  • calling libraries from Swift
  • writing and using Swift frameworks

One problem I've noticed in doing such tests, is that one can easily be confused into thinking something you tried works, but it turns out to have actually used object code or even files left over from a previous attempt.

To avoid these problems, especially with C code, we can follow the steps here.


So here is a list of the short focused items we'll cover.

C code:


C code libraries

For the difference between static and dynamic libraries see here.

The main difference is that a dynamic library can be shared between different programs, and its code isn't actually present in the object code.


Homebrew

One value in looking at these older ways of doing things is just to have some insight into what a library is.

Also, a number of libraries are available for macOS through various package managers including Homebrew.

[not written yet]


Objective-C frameworks:

The modern way on macOS is to use a Framework.

Certainly the simplest way to use C code in a modern Cocoa app is to just add the .c files to the Xcode project. If you already have something like libadd.a or libadd.dylib then things are (much) more complicated.

I found an article that describes how to repackage legacy libraries into Frameworks. I haven't worked through all that yet.


Swift calling Objective-C frameworks


Swift frameworks


Playgrounds