简体   繁体   English

在Xcode项目中包含静态库

[英]Including a static library in a Xcode project

I have developed a static library using the "iPhone OS->Library->Cocoa Touch Static Library" of Xcode. 我已经使用Xcode的“ iPhone OS-> Library-> Cocoa Touch静态库”开发了一个静态库。 I compiled it and it works fine. 我编译了它,并且效果很好。 Then I wanted to include this library in a new project. 然后,我想将此库包含在一个新项目中。 Here is what I've done : 这是我所做的:

  • Create a new Xcode project "View-based application" 创建一个新的Xcode项目“基于视图的应用程序”
  • Project->Add To Project : I added my static library .xcodeproj file 项目->添加到项目:我添加了我的静态库.xcodeproj文件
  • 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", referenced from: 从以下位置引用的“ _OBJC_CLASS _ $ _ GenUIImage”:

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

Symbol(s) not found 找不到符号

Collect2: Id returned 1 exit status Collect2:ID返回了1个退出状态

I do not get what I did wrong. 我不明白我做错了什么。 Please help. 请帮忙。 Thanks in advance 提前致谢

I found the solution. 我找到了解决方案。 I dragged & dropped the .a (library file) into the "Link Binary With Libraries" of the main project target. 我将.a(库文件)拖放到主要项目目标的“使用库链接二进制文件”中。

However I have an other problem. 但是我还有另一个问题。

My static library contains a class that needs the AudioToolbox framework. 我的静态库包含一个需要AudioToolbox框架的类。 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? 有没有办法避免在主项目中重复框架?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM