Xcode 3.1.1 和静态库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/87979/
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-14 18:24:05  来源:igfitidea点击:

Xcode 3.1.1 and static libraries

xcodemacos

提问by Charles Nicholson

I'm an experienced VS.NET user and trying to get up and running on Xcode 3.1.1.
Here's what I'm trying to accomplish:

我是一位经验丰富的 VS.NET 用户,并试图在 Xcode 3.1.1 上启动和运行。
这是我想要完成的:

I'd like a static library ("Lib") to have its own xcodeproj file. I'd an executable application ("App") that makes use of Lib to reference Lib's xcodeproj file so that changes to Lib cause App to relink. Ideally, I'd like to be able to edit Lib's source files inside App's Xcode workspace so I don't have to task around all the time to make changes.

我想要一个静态库(“Lib”)有自己的 xcodeproj 文件。我有一个可执行应用程序(“App”),它使用 Lib 来引用 Lib 的 xcodeproj 文件,以便对 Lib 的更改会导致 App 重新链接。理想情况下,我希望能够在 App 的 Xcode 工作区中编辑 Lib 的源文件,这样我就不必一直忙于进行更改。

I figured out from the online help that I can simply drag the static lib xcodeproj in to my app's project and it gets the reference. I see that once my static lib xcodeproj is in my app's project, I can simply drag it to the App's target and it understands that App depends on Lib. This seems like the right path, but things aren't quite working the way I'd like yet.

我从在线帮助中发现,我可以简单地将静态库 xcodeproj 拖到我的应用程序的项目中,并获得参考。我看到一旦我的静态库 xcodeproj 在我的应用程序的项目中,我就可以简单地将它拖到应用程序的目标上,并且它知道 App 依赖于 Lib。这似乎是正确的道路,但事情还没有完全按照我想要的方式进行。

Here are my questions:

以下是我的问题:

  1. It seems that simply having App depend on Lib doesn't cause App to link with Lib. It seems that I have to explicitly drag libLib.a from the Lib folder into App's "Link Binary With Libraries" build stage. In VS.NET, simply specifying the project as a solution dependency adds it to the link line. I just want to make sure I'm not missing anything.

  2. When I have App open in Xcode and I drag Lib.xcodeproj into it, I don't get any of Lib's source files there. I only get libLib.a under the "Lib.xcodeproj" folder. In VS.NET, I can edit Lib's source files right there and rebuild it, etc... but with this approach in Xcode, changes to Lib.cpp don't cause Lib to rebuild when I rebuild App. Ideally, I'd get all of Lib's source files and targets to show up when I drag Lib.xcodeproj into App. Is there any way of doing this?

  1. 似乎只是让 App 依赖于 Lib 并不会导致 App 与 Lib 链接。似乎我必须明确地将 libLib.a 从 Lib 文件夹拖到 App 的“Link Binary With Libraries”构建阶段。在 VS.NET 中,只需将项目指定为解决方案依赖项即可将其添加到链接行。我只是想确保我没有遗漏任何东西。

  2. 当我在 Xcode 中打开 App 并将 Lib.xcodeproj 拖入其中时,我没有在那里获得任何 Lib 的源文件。我只在“Lib.xcodeproj”文件夹下得到 libLib.a 。在 VS.NET 中,我可以在那里编辑 Lib 的源文件并重建它,等等......但是在 Xcode 中使用这种方法,当我重建 App 时,对 Lib.cpp 的更改不会导致 Lib 重建。理想情况下,当我将 Lib.xcodeproj 拖入 App 时,我会显示所有 Lib 的源文件和目标。有没有办法做到这一点?

Thanks in advance for any responses!

提前感谢您的任何答复!

回答by Chris Hanson

You're correct that making target A depend upon target B (whether within the same project or across projects) does notcause target A to link against target B. You need to specify them distinctly; this is because they're separate concepts, and you might have dependencies between targets that you don'twant to link to each other —?for example, a command-line tool that gets built by target C and is used as part of the build process for target A.

你正确的,使得一个目标依赖于目标B(无论是在同一项目内或跨项目)不会引起目标一个打击目标B.你需要明确指定它们的链接; 这是因为他们是不同的概念,你可能有目标之间的依赖关系,你希望彼此链接-例如,一个命令行得到由目标C建成并用作部分工具目标 A 的构建过程。

Also, you're correct that referencing project B from within project A will not let you see project B's source code in project A's window. That's because Xcode does not have the same "workspace" model that Visual Studio and Eclipse do; you above alluded to the existence of "a workspace containing project A" but Xcode doesn't really have any such thing, just a window representingproject A.

此外,您是正确的,从项目 A 中引用项目 B 不会让您在项目 A 的窗口中看到项目 B 的源代码。这是因为 Xcode 没有与 Visual Studio 和 Eclipse 相同的“工作区”模型;您在上面提到了“包含项目 A 的工作区”的存在,但 Xcode 并没有任何这样的东西,只是一个代表项目 A的窗口。

回答by pestophagous

Open the App project. Right-click on the App target and choose "Get Info." Then go to the "General Tab" and find "Direct Dependencies." Click the ( + ) (plus sign) button to add a direct dependency. The Lib.xcodeproj should appear among a list of possibilities for you. Choose the Lib target from that list.

打开应用程序项目。右键单击应用程序目标并选择“获取信息”。然后转到“常规选项卡”并找到“直接依赖项”。单击 (+)(加号)按钮以添加直接依赖项。Lib.xcodeproj 应该出现在您的可能性列表中。从该列表中选择 Lib 目标。

That should accomplish that the Lib project must build (or rebuild) when you build the App target.

这应该实现了在构建 App 目标时必须构建(或重建)Lib 项目。

(Editing my own post now. I realize I said nothing about point number 2 in the question. I am actually still thinking about number 2. I am not sure if that is possible or not.)

(现在编辑我自己的帖子。我意识到我没有提到问题中的第 2 点。实际上我还在考虑第 2 点。我不确定这是否可能。)

回答by pestophagous

I am also a fairly new user of Xcode. Most of what I know I learned from an Xcode book by James Bucanek (ISBN 047175479x). It is an older book that was written for/with Xcode 2.2, but I find that pretty much all of it still applies for me today, and I currently use Xcode 3.1

我也是一个相当新的 Xcode 用户。我所知道的大部分知识都是从 James Bucanek (ISBN 047175479x) 的一本 Xcode 书中学到的。这是一本旧书,是为/使用 Xcode 2.2 编写的,但我发现几乎所有内容今天仍然适用于我,我目前使用 Xcode 3.1

You can probably find a cheap used copy if you are interested.

如果您有兴趣,您可能会找到便宜的二手副本。

回答by Alex

I'm also novice to Xcode 3.1, just played with mentioned by you issues and found that there is no problem regarding to your second question. Whatever application you use to edit the dependence library source code, your main project will rebuild the dependence target. I checked it by:

我也是 Xcode 3.1 的新手,刚刚玩过你提到的问题,发现你的第二个问题没有问题。无论您使用什么应用程序来编辑依赖库源代码,您的主项目都会重建依赖目标。我通过以下方式检查了它:

  1. edited the source file, of the library your app depend on, by notepad application.
  2. Selected dependence library project reference, mouse right-click, and select 'Open With Finder', then selected wanted source file and edited it.
  1. 通过记事本应用程序编辑了您的应用程序所依赖的库的源文件。
  2. 选中依赖库项目引用,鼠标右击,选择'Open With Finder',然后选中想要的源文件并进行编辑。

Everything working well.

一切正常。