开发者

Building a static library for iOS

开发者 https://www.devze.com 2023-03-08 04:21 出处:网络
I have built a static library for iOS. 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 comp

I have built a static library for iOS. 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.

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 ?

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-afhqjyfitjc开发者_Python百科nbqdmywezdvmryvyp/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. 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. This will add it as a dependency project and automatically build it as a static library and link your project against it.

When using your static library in one of your application projects do the same. It is easier to manage your static library as a dependency project which in turn has ASIHTTPRequest as another level of dependency. 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...

0

精彩评论

暂无评论...
验证码 换一张
取 消