XCode 4.2 和使用静态库导致问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9726000/
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
XCode 4.2 and Using a Static Library Causing Problems
提问by Mike D
Like many others here SO, I am having issues using libraries in my XCode workspace. The idea is I have my main project (MyApp
) and two libraries (lib1
and lib2
) which were added to the workspace after the code was finalized.
像这里的许多其他人一样,我在我的 XCode 工作区中使用库时遇到问题。这个想法是我有我的主要项目 ( MyApp
) 和两个库 (lib1
和lib2
),它们在代码完成后添加到工作区。
For background, lib1
is dependent on lib2, since there are some protocols that need to be implemented in order to make use of lib2
. MyApp
is dependent on both. I have tried following the Apple guides, which implies what I would like to is simple. After that, I have followed pretty much every post here on SO that has come up in my searches (2 days worth of Googling), plus many other blogs and posts that claim to have solutions, many of which are XCode 3 specific.
对于后台,lib1
依赖于 lib2,因为有一些协议需要实现才能使用lib2
. MyApp
两者都依赖。我曾尝试遵循 Apple 指南,这意味着我想要的很简单。在那之后,我关注了几乎所有在我搜索中出现的 SO 帖子(谷歌搜索了 2 天),以及许多其他声称有解决方案的博客和帖子,其中许多是特定于 XCode 3 的。
Yet, my project does not build. I am using Xcode 4.2 on OS 10.6 (upgrading to Lion is not an option). Is there a simple tutorial to follow on how to create a library project, and use this library in an application.
然而,我的项目没有建立。我在 OS 10.6 上使用 Xcode 4.2(升级到 Lion 不是一种选择)。是否有关于如何创建库项目并在应用程序中使用该库的简单教程。
I came across this answerwhile writing this question (where the question had the same error I had), which I will look into, but I have reached the point of copying source files over just to get a demo working.
我在写这个问题时遇到了这个答案(这个问题和我有同样的错误),我会调查一下,但我已经达到了复制源文件只是为了让演示工作的地步。
UPDATE:
更新:
Here is list of issues that have come up. I will add more when they arise:
这是出现的问题列表。当它们出现时,我会添加更多:
**directory not found for option '-L/Users/myhomedir/iphoneprojects/MyApp/../BLProfile/build/Release-iphoneos'**
**directory not found for option '-L/Users/myhomedir/iphoneprojects/MyApp/../BLProfile/build/Release-iphoneos'**
回答by sch
Here is how to create a static library and a project that use it.
以下是如何创建静态库和使用它的项目。
Step 1:Create a workspace: File > New > Workspace. This is not mandatory but it helps organize the projects.
步骤 1:创建工作区:文件 > 新建 > 工作区。这不是强制性的,但它有助于组织项目。
Step 2:Create a static library project: File > New > Project > Framework and Library > Cocoa Touch Static Library. Lets call it MyLib.
第二步:创建一个静态库项目:File > New > Project > Framework and Library > Cocoa Touch Static Library。让我们称之为MyLib。
Step 3:Create an Application Project: File > New > Project > Application> Empty Application, or any other application template. Lets call this project MyApp. If you placed the projects in different folders, you may have to use a different path.
第 3 步:创建应用程序项目:文件 > 新建 > 项目 > 应用程序 > 空应用程序,或任何其他应用程序模板。让我们称这个项目为MyApp。如果您将项目放在不同的文件夹中,则可能必须使用不同的路径。
Now you have the following Projects in the workspace.
现在您在工作区中有以下项目。
Step 4:Configure the app so that it finds the .h
files of the library. To do that, add the parent folder "../"and check the recursivecheckbox.
步骤 4:配置应用程序,以便它找到.h
库的文件。为此,请添加父文件夹“../”并选中递归复选框。
Step 5:Link the app to the library.
第 5 步:将应用程序链接到库。
回答by Ajay
- Open Main Project where you would like to add static library.
- Save as workspace.
- Add library's project package. No need to check copy while adding project package.
- Update Xcode preferences location to Custom-Relative to Workspace. Products as 'Build/Products' and Intermediates as Build/Intermediates
- In your Main project -> target -> build settings, Add Header and Library Search Path as $(BUILD_PRODUCTS_DIR)
- Build Library Project. So a new library will be created in mentioned build path.
- Remove existing library from Build Phases and move to trash. Open Build Phases -> Link Binary With Libraries and add newly created library from build directory.
- 打开您要添加静态库的主项目。
- 另存为工作区。
- 添加库的项目包。添加项目包时无需检查副本。
- 将 Xcode 首选项位置更新为 Custom-Relative to Workspace。产品作为“构建/产品”和中间体作为构建/中间体
- 在您的主项目 -> 目标 -> 构建设置中,将标题和库搜索路径添加为 $(BUILD_PRODUCTS_DIR)
- 构建库项目。因此,将在提到的构建路径中创建一个新库。
- 从构建阶段中删除现有库并移至垃圾箱。打开 Build Phases -> Link Binary With Libraries 并从构建目录添加新创建的库。