我应该如何管理 Xcode 工作区中项目之间的依赖关系?

发布于 2024-10-28 04:11:39 字数 971 浏览 3 评论 0原文

我正在开发一个 iOS 应用程序项目,并将 json-framework 项目添加到工作区。左侧的项目导航器显示这两个项目,构建方案选择器也显示这两个项目的方案。现在我想添加 json-framework 项目中的 libjson.a 目标作为对其他项目中 iOS 应用程序目标的依赖项。预期的结果是,每当构建应用程序目标时,它都会构建(如果需要)库目标并将应用程序目标链接到它。以下是我尝试执行此操作的方法:

  • 将两者构建为同一方案的一部分。我尝试的方法是编辑我的应用程序的方案,将“libjson.a”添加到方案的“构建”部分,并顺便检查“查找隐式依赖项”。然后,我转到应用程序目标的目标编辑器,并在“构建阶段”->“将二进制文件与库链接”中,从工作区库列表中选择“libjson.a”。 当我随后尝试构建该方案时,我看到它构建了库目标,但构建应用程序目标失败,并出现链接器错误“未找到 -ljson 的库” - 这表明它实际上尚未发现该库已构建。事实上,在项目导航器中,该库的应用程序项目下的条目仍然是红色,表明该文件不存在。

  • 将 json 目标添加为显式依赖项。为了尝试这个,我不修改构建方案,而是转到我的应用程序目标的目标编辑器,然后单击“目标依赖项”下的添加按钮。工作区中其他项目的目标均未显示,因此这是不可能的。

  • 将 JSON 项目拖到另一个项目中,然后将目标添加为依赖项。这就是我在 Xcode 3 中所做的。在项目导航器中,我抓取库项目并将其拖动到应用程序项目上。这将打开通常的“添加文件”窗格,我只需单击“完成”即可将其关闭。 现在项目导航器中有两个 库项目条目:一个位于顶层,一个位于应用程序项目下。我现在可以使用目标编辑器将库目标添加为应用程序目标的依赖项,并且可以在链接库阶段链接它而不会出现错误。但它看起来很糟糕:导航器中同一项目有多个条目。有其他方法可以做到这一点吗?

在同一工作区的不同项目中连接这些目标的“Xcode 4-ish”方式应该被视为什么?如果同一工作区中的多个项目实际上无法相互交互,那就显得缺乏。 谢谢, 格雷厄姆.

I'm working on an iOS app project, and add the json-framework project to the workspace. The project navigator on the left shows both projects, and the build scheme selector shows the schemes from both projects too. Now I want to add the libjson.a target from the json-framework project as a dependency on the iOS app target in the other project. The expected result is that whenever the app target is built, it builds (if necessary) the library target and links the app target against it. Here are the ways I've tried to do this:

  • Build both as part of the same scheme. The way I try this is to edit the scheme for my app, adding 'libjson.a' to the 'Build' portion of the scheme, and by the way "Find Implicit Dependencies" is checked. Then I go to the target editor for my app target, and in "Build Phases"->"Link Binary With Libraries", I choose 'libjson.a' from the list of workspace libraries.
    When I subsequently try to build the scheme, I see it build the library target, but building the app target fails with linker error "Library not found for -ljson" - suggesting that it hasn't actually discovered that the library has been built. Indeed in the project navigator, the entry under the app project for the library is still red indicating that the file doesn't exist.

  • Add the json target as an explicit dependency. To try this, I don't modify the build scheme, but go to the target editor for my app target and click the add button under 'Target Dependencies'. No targets from other projects in the workspace show up, so this is a non-starter.

  • Drag the JSON project into the other project, then add the target as a dependency. This is what I would have done in Xcode 3. In the project navigator, I grab the library project and drag it over the app project. This brings up the usual 'add files' pane, which I just dismiss by clicking 'Finish'.
    There are now two entries for the library project in the project navigator: one at the top level, and one under the app project. I can now add the library target as a dependency of the app target using the target editor, and can link against it without error in the link libraries phase. But it looks broken: there are multiple entries for the same project in the navigator. Is there a different way to do this?

What should be considered the "Xcode 4-ish" way of connecting these targets in different projects in the same workspace? It would seem lacking if multiple projects in the same workspace can't actually interact with each other.
Thanks,
Graham.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

记忆里有你的影子 2024-11-04 04:11:39

我刚刚设置了一个测试项目,与您在版本 3 中描述的非常相似,方法是创建一个新工作区并将两个 Xcode 项目拖入其中,如图所示嵌套。

如果您已有同级项目,则可以将其删除。

据我所知,在此基础上进行构建就可以了。

方案设置
Project Layout

我想如果您有两个项目,可能会存在内部路径混乱,并且我倾向于摆弄位置在“视图”->“实用程序”->“文件检查器”中进行设置,看看有什么效果。

在此处输入图像描述
在此处输入图像描述

另一件要尝试的事情是在 Xcode“首选项…”->“源树”中设置路径”并以这种方式引用它们,如下所述:轻松、模块化的代码共享iPhone 应用程序:静态库和跨项目参考

HTH。安迪·W.

I’ve just set a test project up, pretty much as you describe in version 3, by creating a new workspace and dragging the two Xcode project into it, nested as shown.

You can delete the sibling project if you have it already.

Hitting build on this and it just works, as far as I can see.

Scheme Settings
Project Layout

I imagine there is internal path-confusion if you have two projects, and I’d be inclined to fiddle with location settings in "View"->"Utilities"->"File Inspector" and see what effect that has.

enter image description here
enter image description here

Another thing to try is to set your paths up in Xcode "Preferences…"->"Source Trees" and refer to them that way, as described here: Easy, Modular Code Sharing Across iPhone Apps: Static Libraries and Cross-Project References

HTH. Andy W.

虫児飞 2024-11-04 04:11:39

我设法让工作区中的项目之间的依赖关系按照我在此处描述的方式工作: http://blog.carbon Five.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/

不幸的是,我无法找到一种方法让 Xcode 发现隐式依赖项或按照广告的方式对构建中的所有内容进行索引。我找到了解决这两个问题的方法,但我希望随着 Xcode 4 的成熟,需要更少的手动配置。

I managed to get dependencies between projects in a workspace to work as I described here: http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/.

Unfortunately I can't find a way to get Xcode to discover implicit dependencies or index everything in the build as advertised. I found workaround to both but I'm hoping that less manual configuration will be needed as Xcode 4 matures.

握住我的手 2024-11-04 04:11:39

我本来想问同样的问题,认为我自己的解决方案不可能是正确的。但我没有看到这里提到它,而且它似乎确实有效。显然 XCode 4 是一项正在进行中的工作。 :)

我有一个包含两个项目的工作区:一个静态库和一个使用该库的应用程序。这些项目是兄弟项目。每个项目都有自己的方案,并且每个方案都设置为只构建一个目标。换句话说,我向工作区添加了两个项目,仅此而已。

要将静态库添加为应用程序的依赖项,我只需将 libsomething.a 产品从库项目 (Project Navigator) 拖到应用程序目标的“链接二进制文件与库”列表中。就是这样。现在,当我构建应用程序时,首先构建库项目,然后链接。有趣的是,当我修改应用程序的方案以使用不同的配置(例如,发布而不是调试)时,库是使用相同的配置构建的。

所以它有效,并且显然这里正在进行一些自动依赖性检查。但感觉不对。话又说回来,模态方案编辑器/管理器和项目导航器中缺少工作区对象也是如此……我从没想过我会这么说,但 Visual Studio UI (bleh) 更清晰。

I was going to ask the same question, thinking that my own solution couldn't be right. But I don't see it mentioned here, and it does seem to work. Clearly XCode 4 is a work in progress. :)

I have a workspace with two projects: a static library and an app which uses the library. The projects are siblings. Each project has its own scheme, and each scheme is set to only build one target. In other words, I added two projects to the workspace and that's it.

To add the static library as a dependency of the app, I just drag the libsomething.a product from the library project (Project Navigator) into the "Link Binary with Libraries" list for the app target. That's it. Now when I build the app the library project is built first and then linked. Interestingly, when I modify the app's scheme to use a different configuration (eg, Release instead of Debug), the library is built using the same configuration.

So it works, and there is clearly some automatic dependency checking going on here. But it feels wrong. Then again, so does the modal scheme editor/manager and lack of a workspace object in the project navigator... I never thought I'd say it, but the Visual Studio UI (bleh) is a lot clearer.

π浅易 2024-11-04 04:11:39

我执行此操作的防弹解决方案:

在主项目(而不是库)的“构建设置”中创建“每个调试发布/每个架构”设置,以包括
../MyLibProject/build/Debug-iphoneos
或者
../MyLibProject/build/Release-iphonesimulator
或者
等等..
取决于配置(您可以通过单击“调试”或“发布”旁边的 + 来创建此类配置,然后选择“任何 iOS 模拟器 SDK”或“任何 iOS SDK”。
您需要为“标题搜索路径”(如果您的库复制一些标题文件,这很可能)和“库搜索路径”执行此操作。这意味着对于每个设置,您可能最终会得到 4 个不同的路径(debug sim 、 debug ios、release sim、release ios)。
这将确保两个项目的配置匹配。

现在,要自动编译库,即创建依赖项,您可以使用上面给出的“构建阶段 -> 链接到带有库的二进制文件 -> + -> 选择 .a 文件”建议。

这是我设法在 xcode 4.5 上为每个环境正确构建和链接的唯一方法

注意:我什至在“其他链接器标志”中添加了 -lmyLib 标志,但我不确定这是否真的有必要

My bullet-proof solution to do this :

Create "Per Debug-Release / Per Architecture" settings in Build Settings in the Main project (not the lib), to include either
../MyLibProject/build/Debug-iphoneos
or
../MyLibProject/build/Release-iphonesimulator
or
etc..
depending on the configuration (you can create those kind of configuration by clicking on the + next to Debug or Release and choose either "Any iOS Simulator SDK" or "any iOS SDK".
You need to do that for both "Header Search Path" (in case your library copy some headers files, which is more than likely) AND for "Library Search Paths". Which means that for each setting, you'll probably end-up with 4 different paths (debug sim , debug ios, release sim, release ios).
That would make sure the configuration of both projects match.

Now, to auto-compile the lib, that is to create the dependency, you can use the "Build Phase -> Link to Binary With Libraries -> + -> select the .a file" advice given above.

That's the only way I managed to have something that builds and link correctly for every environment on xcode 4.5

Note : I even added the -lmyLib flag in "other linker flags", but i'm not sure that's really necessary

哥,最终变帅啦 2024-11-04 04:11:39

I've had some success with creating framework-like static libraries, though it's not a perfect solution.

好听的两个字的网名 2024-11-04 04:11:39

我看到以下变体:

  1. 项目中的显式依赖[关于]
  2. 工作区中的隐式依赖[关于]

I see the next variants:

  1. Explicit dependency in a project[About]
  2. Implicit dependency in a workspace[About]
·深蓝 2024-11-04 04:11:39

请参阅 Xcode 用户指南:Xcode Concepts -> “工作空间中的项目共享构建目录”下的 Xcode 工作空间。

单个工作区中的所有项目共享一个构建目录。依赖关系会自动发现并根据需要构建:

“Xcode 检查构建目录中的文件以发现隐式依赖关系。例如,如果工作区中包含的一个项目构建了一个与同一工作区中的另一个项目链接的库,则 Xcode 会在构建该库之前自动构建该库。其他项目,即使构建配置未明确此依赖关系,您也可以根据需要使用显式构建设置覆盖此类隐式依赖关系。”

See the Xcode user guide: Xcode Concepts -> Xcode workspace under 'Projects in a Workspace Share a Build Directory'.

All projects in a single workspace share a build directory. Dependencies are discovered automatically and build if needed:

"Xcode examines the files in the build directory to discover implicit dependencies. For example, if one project included in a workspace builds a library that is linked against by another project in the same workspace, Xcode automatically builds the library before building the other project, even if the build configuration does not make this dependency explicit. You can override such implicit dependencies with explicit build settings if necessary. For explicit dependencies, you must create project references."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文