在命令行工具中使用框架 [英] Using frameworks in a command line tool
问题描述
我在Xcode中使用Cocoa构建了一个命令行实用程序(Foundation工具)。该工具使用第三方框架。
I've built a command-line utility (Foundation tool) in Xcode, using Cocoa. The tool makes use of a 3rd party framework.
在Xcode中一切正常,但如何部署此程序?
Everything works OK in Xcode, but how do I deploy this program?
如果我从Finder运行应用程序,它找不到该库,因为它在 ../ Frameworks / etc。
。我可以静态链接第三党框架?
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?
推荐答案
不幸的是,没有办法绑定一个框架与命令行实用程序在OS X和我怀疑框架你正在链接到期望捆绑在应用程序包的Frameworks /目录中。如果您可以访问框架源代码,则可以编译静态库并将其静态链接到应用程序(或直接在应用程序目标中包含源代码)。如果您没有源代码,或者您不想由于某种原因静态链接库,则还有两个选项:
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:
-
如果您可以访问系统/ Library / Frameworks文件夹,您可以安装第三方框架。这需要在构建时将框架的安装路径(
INSTALL_PATH
构建设置)设置为/ Library / Frameworks
您使用install_name_tool
将框架安装路径更改为/ Library / Frameworks
(如果您没有框架的源代码)。
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 theinstall_name_tool
to change the frameworks install path to/Library/Frameworks
(if you don't have the framework's source code).
使用命令行实用程序构建应用程序包(就像创建GUI应用程序一样)在AppBundle.app/Contents/MacOS/)。然后,您可以将第三方框架复制到应用程序包的frameworks目录。然后,您可以将应用程序包放置在任何位置,并创建指向命令行实用程序的符号链接。
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.
选项1
你可以找到关于构建,链接和安装框架的更多信息。 Apple的框架编程指南
You can find more information on building, linking, and installing frameworks in Apple's Frameworks Programming Guide.
这篇关于在命令行工具中使用框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!