在Xcode项目中包含静态库 [英] Including a static library in a Xcode project

查看:195
本文介绍了在Xcode项目中包含静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Xcode的iPhone OS-> Library-> Cocoa Touch Static Library开发了一个静态库。我编译它,它工作正常。然后我想将这个库包含在一个新项目中。以下是我所做的:

I have developed a static library using the "iPhone OS->Library->Cocoa Touch Static Library" of Xcode. I compiled it and it works fine. Then I wanted to include this library in a new project. Here is what I've done :


  • 创建一个新的Xcode项目基于视图的应用程序

  • 项目 - >添加到项目:我添加了我的静态库.xcodeproj文件

  • 项目 - >编辑活动目标


    • 在常规选项卡中:我在直接依赖关系中添加了静态库

    • 在构建选项卡中:我在标题搜索路径中添加了标题的路径在搜索路径部分中

    • Create a new Xcode project "View-based application"
    • Project->Add To Project : I added my static library .xcodeproj file
    • Project->Edit Active Target
      • In General tab : I've added the static library in the "Direct Dependencies"
      • In Build tab : I've added the path of the headers in the "Header Search Paths" In "Search Paths" section

      然后我尝试使用其中一个类我已经放入了我的静态库,但是我收到了链接错误:

      Then I tried to use one of the classes I've put in my static library, but I get a linking error :

      _ OBJC_CLASS _ $ _ GenUIImage,引用自:

      "_OBJC_CLASS_$_GenUIImage", referenced from:

      TestViewController.o中的Objc-class-ref-to-GenUIImage

      Objc-class-ref-to-GenUIImage in TestViewController.o

      未找到符号

      Collect2:Id返回1退出状态

      Collect2: Id returned 1 exit status

      我不知道我做错了什么。请帮忙。
      提前致谢

      I do not get what I did wrong. Please help. Thanks in advance

      推荐答案

      我找到了解决方案。我拖着&将.a(库文件)放入主项目目标的Link Binary With Libraries。

      I found the solution. I dragged & dropped the .a (library file) into the "Link Binary With Libraries" of the main project target.

      但是我有另一个问题。

      However I have an other problem.

      我的静态库包含一个需要AudioToolbox框架的类。我在静态库中添加了它。但是我需要在项目中添加框架。有没有办法避免在主项目中重复框架?

      My static library contains a class that needs the AudioToolbox framework. I added it in my static library. However I need to add the framework also inside the project. Is there a way to avoid duplicating the framework in the main project?

      这篇关于在Xcode项目中包含静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆