Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using frameworks in a command line tool

Tags:

xcode

macos

cocoa

I've built a command-line utility (Foundation tool) in Xcode, using Cocoa. The tool makes use of a 3rd party framework.

Everything works OK in Xcode, but how do I deploy this program?

If I run the app from Finder, it can't find the library because it's looking in ../Frameworks/etc. Can I statically link in the 3rd party framework?

like image 894
Norman Avatar asked Mar 10 '09 15:03

Norman


People also ask

How do I use framework in Xcode?

To include a framework in your Xcode project, choose Project > Add to Project and select the framework directory. Alternatively, you can control-click your project group and choose Add Files > Existing Frameworks from the contextual menu.

What is the use of framework in Swift?

In Swift parlance, a module is a compiled group of code distributed together. A framework is one type of module while an app is another. Note: If you want to learn more about frameworks, read What are Frameworks?.


1 Answers

Unfortunately, there is no way to bundle a framework with a command-line Utility in OS X and I suspect that the framework you're linking to is expecting to be bundled in the app bundle's Frameworks/ directory. If you have access to the framework source code, you can compile a static library and statically link it to your application (or include the source in your application target directly). If you don't have the source code or you don't want to statically link the library for some reason, there are two remaining options:

  1. If you have access to the system-wide /Library/Frameworks folder, you can install the 3rd party framework there. This require that the framework's Installation Path (the INSTALL_PATH build setting) be set to /Library/Frameworks at build time or that you use the install_name_tool to change the frameworks install path to /Library/Frameworks (if you don't have the framework's source code).

  2. Build an application bundle (as if you were building a GUI app) with your command-line utility as the app bundle's executable (i.e. in AppBundle.app/Contents/MacOS/). You can then copy the 3rd party framework to the app bundle's frameworks directory. You can then put the app bundle anywhere you want and create a symbolic link to the command line utility.

Option 1 is definitely the more accepted approach, but I've used option 2 when there was a valid reason.

You can find more information on building, linking, and installing frameworks in Apple's Frameworks Programming Guide.

like image 197
Barry Wark Avatar answered Oct 04 '22 04:10

Barry Wark