将静态库链接到XCode 4中的iOS项目。

时间:2022-09-18 14:19:34

I have a project (AQGridView) that compiles to a static library, but I can't seem to add it to my project.

我有一个编译到静态库的项目(AQGridView),但是我似乎不能将它添加到我的项目中。

Dragging in the project to my project creates a workspace, and if I try to link the libAQGridView.a file from the DerivedData directory it doesn't recognize it as a library. I'm not sure what I'm doing wrong.

将项目拖到我的项目中创建一个工作空间,如果我尝试链接libAQGridView。一个来自DerivedData目录的文件,它不承认它是一个库。我不知道我做错了什么。

This is the AQGridView project. Does anyone know specifically how to use it in an XCode 4 project?

这是AQGridView项目。有人知道如何在XCode 4项目中使用它吗?

6 个解决方案

#1


92  

I do this as follows:

我这样做如下:

  1. Drag in the static library project. If you have the static library project open in Xcode, close it now.
  2. 拖动静态库项目。如果您在Xcode中打开了静态库项目,现在就关闭它。
  3. Select the main project in the project navigator (the project I'm adding the static library to) and in the editor, under the header TARGETS in the left-hand column, select my main project's target and navigate to the Build Phases tab.
  4. 在项目导航器(我正在添加静态库的项目)和编辑器中选择主项目,在左侧列的标题目标下,选择我的主要项目的目标并导航到Build阶段选项卡。
  5. Click the "+" for Target Dependencies and add the library icon target dependency from the added static library project.
  6. 单击“+”以获取目标依赖项,并从添加的静态库项目中添加库图标目标依赖项。
  7. Click the "+" for Link Binary with Libraries and add the library icon that is under the folder "Workspace".
  8. 单击“+”链接二进制文件与库,并添加文件夹“工作区”下的库图标。
  9. It may also be necessary to enter a Header Search Path for the headers of the static library project if that is how the headers are linked in the static library project itself.
  10. 如果在静态库项目本身中是如何链接头的,那么还可能需要为静态库项目的头输入头搜索路径。

If you don't see the static library project as nested under the main project in the main project's project navigator, the most likely reason for that is that the static library's own Xcode project is still open. Quit Xcode and open up the main project that has the nested static library project in it without opening up the original static library project itself, and you should see it appearing as a nested project in your main project.

如果您没有看到在主项目的项目导航器的主项目下嵌套的静态库项目,那么最可能的原因是静态库的自己的Xcode项目仍然是开放的。退出Xcode并打开包含嵌套静态库项目的主项目,而不打开原始的静态库项目本身,您应该看到它作为一个嵌套项目出现在您的主项目中。

#2


14  

Xcode menu > View > Utilities > File Inspector

Xcode菜单>视图>实用工具>文件检查器。

Select the static library file, and then set 'File Type' as 'Mach-O object code' in 'Identity and Type'.

选择静态库文件,然后将“file Type”设置为“Identity and Type”中的“Mach-O对象代码”。

#3


5  

Workspaces are supposed to make this easier, but I don't know that they do. The way I do it is create a workspace, add my main project, add my library project. Then go into the main project's build phases and add the library in the "Link binary with libraries" section and add the library. That should be all that is necessary, at least that's my reading, but it isn't. What I do is go into Xcode preferences, then to the Source Trees pane. Add a source tree that points to your static library's headers, then go back to the build settings for your project, then to the Header Search Paths key, and enter ${foo} there, where "foo" is whatever you called the source tree.

工作空间应该让这变得更容易,但我不知道他们会这么做。我的方法是创建一个工作空间,添加我的主项目,添加我的库项目。然后进入主项目的构建阶段,并将库添加到“与库的链接二进制文件”部分中,并添加库。那应该是所有必要的,至少这是我的阅读,但它不是。我所做的是进入Xcode首选项,然后到源树窗格。添加指向静态库头的源树,然后返回到项目的构建设置,然后到头搜索路径键,然后输入${foo},其中“foo”就是您所称的源树。

That's what works for me, though I don't know if that's the best or easiest way to do it.

这对我来说很有效,虽然我不知道这是最好还是最简单的方法。

#4


5  

Find your .a file in finder, and drag it into your project.

在finder中找到一个文件,并将其拖到项目中。

Select the 'copy items into destination group's folder (if needed)', and add your headers to your project.

选择“复制项到目标组的文件夹(如果需要)”,并将您的标题添加到项目中。

Now, XCode 4 should automatically link against that framework for you.

现在,XCode 4应该自动链接到这个框架。

Here is what the library should look like in your project:

以下是你的项目中图书馆的样子:

将静态库链接到XCode 4中的iOS项目。

#5


3  

Follow Apple's documentation.

遵循苹果的文档。

In brief:

简而言之:

  1. Link your target against the library.
  2. 把你的目标和图书馆联系起来。
  3. Add -ObjC to 'Other Linker Flags' (OTHER_LDFLAGS) under the target's build settings.
  4. 在目标的构建设置下添加-ObjC到“其他链接器标志”(OTHER_LDFLAGS)。

Also, I needed to add the library to the scheme of my main project since the library was not visible in the target's dependencies.

此外,我还需要将库添加到我的主项目的scheme中,因为目标的依赖项中不可见库。

#6


0  

The Halle's answer works for me with one addition:

黑尔的回答对我有帮助:

  1. Check in Build Settings of the static library project the Private( or Public) Headers Folder Path value and copy it.
  2. 在静态库的构建设置中检查私有(或公共)标头文件夹路径值并复制它。
  3. Add copied value to the client project Build Settings Header Search Path or User Header Search Path depending of the include directive you are using
  4. 根据所使用的include指令,将复制的值添加到客户端项目构建设置头搜索路径或用户头搜索路径中。

#1


92  

I do this as follows:

我这样做如下:

  1. Drag in the static library project. If you have the static library project open in Xcode, close it now.
  2. 拖动静态库项目。如果您在Xcode中打开了静态库项目,现在就关闭它。
  3. Select the main project in the project navigator (the project I'm adding the static library to) and in the editor, under the header TARGETS in the left-hand column, select my main project's target and navigate to the Build Phases tab.
  4. 在项目导航器(我正在添加静态库的项目)和编辑器中选择主项目,在左侧列的标题目标下,选择我的主要项目的目标并导航到Build阶段选项卡。
  5. Click the "+" for Target Dependencies and add the library icon target dependency from the added static library project.
  6. 单击“+”以获取目标依赖项,并从添加的静态库项目中添加库图标目标依赖项。
  7. Click the "+" for Link Binary with Libraries and add the library icon that is under the folder "Workspace".
  8. 单击“+”链接二进制文件与库,并添加文件夹“工作区”下的库图标。
  9. It may also be necessary to enter a Header Search Path for the headers of the static library project if that is how the headers are linked in the static library project itself.
  10. 如果在静态库项目本身中是如何链接头的,那么还可能需要为静态库项目的头输入头搜索路径。

If you don't see the static library project as nested under the main project in the main project's project navigator, the most likely reason for that is that the static library's own Xcode project is still open. Quit Xcode and open up the main project that has the nested static library project in it without opening up the original static library project itself, and you should see it appearing as a nested project in your main project.

如果您没有看到在主项目的项目导航器的主项目下嵌套的静态库项目,那么最可能的原因是静态库的自己的Xcode项目仍然是开放的。退出Xcode并打开包含嵌套静态库项目的主项目,而不打开原始的静态库项目本身,您应该看到它作为一个嵌套项目出现在您的主项目中。

#2


14  

Xcode menu > View > Utilities > File Inspector

Xcode菜单>视图>实用工具>文件检查器。

Select the static library file, and then set 'File Type' as 'Mach-O object code' in 'Identity and Type'.

选择静态库文件,然后将“file Type”设置为“Identity and Type”中的“Mach-O对象代码”。

#3


5  

Workspaces are supposed to make this easier, but I don't know that they do. The way I do it is create a workspace, add my main project, add my library project. Then go into the main project's build phases and add the library in the "Link binary with libraries" section and add the library. That should be all that is necessary, at least that's my reading, but it isn't. What I do is go into Xcode preferences, then to the Source Trees pane. Add a source tree that points to your static library's headers, then go back to the build settings for your project, then to the Header Search Paths key, and enter ${foo} there, where "foo" is whatever you called the source tree.

工作空间应该让这变得更容易,但我不知道他们会这么做。我的方法是创建一个工作空间,添加我的主项目,添加我的库项目。然后进入主项目的构建阶段,并将库添加到“与库的链接二进制文件”部分中,并添加库。那应该是所有必要的,至少这是我的阅读,但它不是。我所做的是进入Xcode首选项,然后到源树窗格。添加指向静态库头的源树,然后返回到项目的构建设置,然后到头搜索路径键,然后输入${foo},其中“foo”就是您所称的源树。

That's what works for me, though I don't know if that's the best or easiest way to do it.

这对我来说很有效,虽然我不知道这是最好还是最简单的方法。

#4


5  

Find your .a file in finder, and drag it into your project.

在finder中找到一个文件,并将其拖到项目中。

Select the 'copy items into destination group's folder (if needed)', and add your headers to your project.

选择“复制项到目标组的文件夹(如果需要)”,并将您的标题添加到项目中。

Now, XCode 4 should automatically link against that framework for you.

现在,XCode 4应该自动链接到这个框架。

Here is what the library should look like in your project:

以下是你的项目中图书馆的样子:

将静态库链接到XCode 4中的iOS项目。

#5


3  

Follow Apple's documentation.

遵循苹果的文档。

In brief:

简而言之:

  1. Link your target against the library.
  2. 把你的目标和图书馆联系起来。
  3. Add -ObjC to 'Other Linker Flags' (OTHER_LDFLAGS) under the target's build settings.
  4. 在目标的构建设置下添加-ObjC到“其他链接器标志”(OTHER_LDFLAGS)。

Also, I needed to add the library to the scheme of my main project since the library was not visible in the target's dependencies.

此外,我还需要将库添加到我的主项目的scheme中,因为目标的依赖项中不可见库。

#6


0  

The Halle's answer works for me with one addition:

黑尔的回答对我有帮助:

  1. Check in Build Settings of the static library project the Private( or Public) Headers Folder Path value and copy it.
  2. 在静态库的构建设置中检查私有(或公共)标头文件夹路径值并复制它。
  3. Add copied value to the client project Build Settings Header Search Path or User Header Search Path depending of the include directive you are using
  4. 根据所使用的include指令,将复制的值添加到客户端项目构建设置头搜索路径或用户头搜索路径中。