xcode 如何将私有框架添加到目标依赖项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12322010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:26:16  来源:igfitidea点击:

How to add Private Framework to Target Dependencies?

xcodemacosxcode4frameworksbuild

提问by hpique

I'm trying to embed a private framework(last paragraph) in my application bundle using XCode 4 and following Apple's (seemingly) outdated instructions.

我正在尝试使用 XCode 4 并遵循 Apple 的(看似)过时的说明在我的应用程序包中嵌入一​​个私有框架(最后一段)。

In my case, I'm Using Separate Xcode Projects For Each Target. This is the final step:

就我而言,我为每个 Target 使用单独的 Xcode 项目。这是最后一步:

In the General tab of the inspector window, add your framework as a dependency for the application. Adding this dependency causes Xcode to build the framework target before building the application target.

The build dependency you establish in the application target causes the framework to be built before the application. This is important because it guarantees that a built version of your framework will be available to link against and to embed in the application. Because of this dependency, you can set the active target of your Xcode project to your application and leave it there. Building the application now builds the framework and copies it to the application bundle directory, creating the necessary linkage between the two.

在检查器窗口的常规选项卡中,添加您的框架作为应用程序的依赖项。添加此依赖项会导致 Xcode 在构建应用程序目标之前构建框架目标。

您在应用程序目标中建立的构建依赖项会导致在应用程序之前构建框架。这很重要,因为它保证您的框架的构建版本可用于链接和嵌入应用程序。由于这种依赖性,您可以将 Xcode 项目的活动目标设置为您的应用程序并将其保留在那里。构建应用程序现在构建框架并将其复制到应用程序包目录,在两者之间创建必要的链接。

Yet, when in click on the + button in Target Dependenciesthe framework doesn't show up. How can I establish a build dependency between the private framework and the application target in Xcode 4?

但是,当单击Target Dependencies 中的+ 按钮时,框架不会显示。如何在 Xcode 4 中的私有框架和应用程序目标之间建立构建依赖关系?

Edit: I should clarify that I already got the private framework working. I just want to avoid having cleaning the project every time a change to the framework is made, and make sure the framework is built before the application target.

编辑:我应该澄清一下,我已经让私有框架正常工作了。我只是想避免每次对框架进行更改时都清理项目,并确保在应用程序目标之前构建框架。

回答by hpique

Managed to solve this by adding the private framework project as a subproject, then adding the framework target in Target Dependencies.

通过将私有框架项目添加为子项目,然后在Target Dependencies 中添加框架目标,设法解决了这个问题。

However, in my case the framework target didn't show as an option in Target Dependenciesuntil I deleted DerivedData. That nasty little bug drove me crazy.

但是,就我而言,在我删除 DerivedData 之前,框架目标并未在目标依赖项中显示为选项。那个讨厌的小虫子把我逼疯了。

回答by SRI

Select your project in the Xcode and then you can find the Project and Target at the right side. Then Select Target and go to LinkBinary with Libraries and then one window will come and there at the bottom left there is an option called Add other.

在 Xcode 中选择您的项目,然后您可以在右侧找到 Project 和 Target。然后选择目标并转到 LinkBinary with Libraries,然后会出现一个窗口,在左下角有一个名为 Add other 的选项。

回答by Rapha?l

If you want to add your private framework without including it as a sub project, you have to add a Copy Filestask for it:

如果要添加私有框架而不将其作为子项目包含,则必须为其添加复制文件任务:

Copy Files task

复制文件任务

Select your framework with the +button and choose Frameworksfor Destination.

选择与你的框架+按钮,然后选择Frameworks目标

You don't need to add anything in Target Dependencies.

您不需要在Target Dependencies 中添加任何内容。

Also for this to work, make sure Runpath Search Pathsvalue is @executable_path/Frameworksin the Build Settingstab.

同样要使其工作,请确保Runpath Search Paths@executable_path/Frameworks位于Build Settings选项卡中。

回答by Wayne

You first need to add the other project's .xcodeprojto the project as a subproject:

您首先需要将另一个.xcodeproj项目作为子项目添加到项目中:

  1. Right-click the Frameworksgroup (or whatever/wherever else)
  2. Select Add Files to "<Project>..."
  3. Select the other project's .xcodeproj
  4. That other project's targets will now appear in the Target Dependenciesmenu
  1. 右键单击Frameworks组(或任何/任何其他地方)
  2. 选择 Add Files to "<Project>..."
  3. 选择其他项目的 .xcodeproj
  4. 其他项目的目标现在将出现在Target Dependencies菜单中