Creating a static structure for OS X

Using soft hacking, you can create static frameworks for iOS. Static frames are quite convenient to use: you can simply delete them in new projects without additional steps (for example, add them to the assembly and add header search paths).

I recently started doing OS X programming, and the first thing I noticed was that static frameworks didn't seem to be available. Dynamic structures are obviously accessible and recommended, but since I want to create a small private infrastructure designed to use the application (not to install in /Library/Frameworks ), using the dynamic structure in new application projects still requires a few additional steps .

In my ideal world, I would create a static framework (a framework that contains header files and a compiled .a file), drag the framework into a new project and start coding. Is there any way to make such a static structure for OS X?

PS I already tried to set the output type of Mach-O to a "static library" in a regular framework project, but I just get the error message Framework target has invalid MACH_O_TYPE value of 'staticlib'. .

+7
source share
2 answers

You can create a dynamic structure in Mac OS X. In your dynamic structure, you can set LD_DYLIB_INSTALL_NAME as @ rpath / Foo.framework / Versions / A / Foo

If you have an application that wants to link this framework, make sure you run

  install_name_tool -add_rpath <rpath> <full-path-to-app-binary> 

So if I have Foo.app

  install_name_tool -add_rpath Foo.app/Contents/Library Foo.app/Contents/MacOS/Foo 

Now, if you just copy Foo.framework to the Contents / Library, it should load, and everything should work.

Hope this helps.

It would probably be easier to use a static library with public headers. When you create a static library, you can automatically copy the headers for Xcode. And for your purpose, you can add a folder to your search path.

If you use a static library, Xcode will remove some dead code that you really don't need, but compiled into a static lib.

+2
source

Static frameworks are not actually supported on OS X. They are still rather fragile and solve a specific problem that exists in iOS, but not in OS X.

If you want developers to be able to use the library you created, you have several options:

  • Use Cocoapods . They have a tutorial to publish your library on CocoaPods. This is probably the easiest way to distribute the library on OS X.
  • Library package as a framework. If you set the installation name correctly (up to @rpath/<library name> ), the downstream developer just needs to copy the framework into his Xcode project and set the search path at runtime of his application to @executable_path/../Frameworks ).
+1
source

All Articles