简体   繁体   English

为 iOS 构建 static 库

[英]Building a static library for iOS

I have built a static library for iOS.我为 iOS 构建了一个 static 库。 My problem is that I use ASIHTTPRequest as an example in my library, and when I add my library to an app that already uses the ASIHTTPRequest library, I get compiler errors, until I remove all ASIHTTPRequest.m files from the project that uses my library.我的问题是我在我的库中使用 ASIHTTPRequest 作为示例,当我将我的库添加到已经使用 ASIHTTPRequest 库的应用程序时,我得到编译器错误,直到我从使用我的库的项目中删除所有 ASIHTTPRequest.m 文件.

Is there a way around this?有没有解决的办法? Like for example build the static library and make it require the ASIHTTP libraries instead of them being added to the project?例如构建 static 库并使其需要 ASIHTTP 库而不是将它们添加到项目中?

EDIT:编辑:

Here is an example of the error I get once I "archive" the project.这是我“归档”项目后遇到的错误示例。

ld: duplicate symbol _main in /Users/tj/Library/Developer/Xcode/DerivedData/db-afhqjyfitjcnbqdmywezdvmryvyp/ArchiveIntermediates/db/IntermediateBuildFilesPath/db.build/Release-iphoneos/db.build/Objects-normal/armv6/fmdb.o and /Users/tj/Library/Developer/Xcode/DerivedData/db-afhqjyfitjcnbqdmywezdvmryvyp/ArchiveIntermediates/db/IntermediateBuildFilesPath/db.build/Release-iphoneos/db.build/Objects-normal/armv6/main.o for architecture armv6
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1

Trausti特劳斯蒂

What I would suggest is to make ASIHTTPRequest into a static library of its own, by adding it as a dependency project in your static library's project.我建议将 ASIHTTPRequest 制作为自己的 static 库,方法是将其作为依赖项项目添加到 static 库的项目中。 Essentially what you do, is to create an xcode project, pack ASIHTTPRequest into it, close that project, then drag&drop the ASIHTTPRequest project file into your static library project's file navigator.基本上你所做的是创建一个 xcode 项目,将 ASIHTTPRequest 打包到其中,关闭该项目,然后将 ASIHTTPRequest 项目文件拖放到 static 库项目的文件导航器中。 This will add it as a dependency project and automatically build it as a static library and link your project against it.这会将其添加为依赖项目并自动将其构建为 static 库并将您的项目链接到它。

When using your static library in one of your application projects do the same.在您的一个应用程序项目中使用您的 static 库时,请执行相同的操作。 It is easier to manage your static library as a dependency project which in turn has ASIHTTPRequest as another level of dependency.将 static 库作为依赖项项目来管理更容易,而 ASIHTTPRequest 作为另一个依赖项级别。 This way both of your projects will be able to see its headers, and link against it and there will be no duplicate symbol issues.这样,您的两个项目都将能够看到其标题,并对其进行链接,并且不会出现重复符号问题。

If you are trying to publish your static library to other developers then it is a more difficult situation...如果您尝试将 static 库发布给其他开发人员,那么情况会更加困难......

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

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