Open Source for non-ARC (Automatic Reference Counting) and ARC Users - iphone

We have some open source libraries that are distributed via code into other projects via git modules with Xcode. Some of the projects would remain with explicit retains/release while other projects would like to leverage Automatic Reference Counting. Is there anyway for the same source to be compilable in Xcode projects with and without ARC? Would it work if it was compiled into a static library?

If you bundle a project that compiles your open source library as a static library, and the other projects link against your static library instead of compiling the source directly, then that would work. The other projects can embed your library's project file if they want, so that your library will get compiled before theirs, or you can just distribute the static library pre-compiled.

Related

Add .framwork to a Swift Package?

I have a Swift package I would like to make public, however I do not want the source code for all of the files shared.
My solution was to bundle the private source code into a .framework and have the swift package call the private source code.
However I cannot seem to be able to add the .framework into the Swift Package project. Any help?
There is an accepted proposal for binary dependencies in SwiftPM. So when that feature ships you will be able to zip up your framework, if it is an xcframework, and link against it. Until then you can only use unsafe linker flags to do so which means you can’t use the package with Xcode unless it is a local package.

How to build ZBar SDK with the project instead of using the static library?

I am building an iOS, code scanner project using ZBar SDK. I am trying to build my project directly from the source of ZBar, rather than including the libzbar.a static library.
I have downloaded the ZBar source which includes the XCode project to build libzbar.a. I tried copying all source files from the project but it didn't work. I keep on getting undefined symbol errors.
What source files should be included, considering that I need to support only iOS?
Should the folder structure be strictly followed to build the project?
Would there be any need of build settings if I direcly include the source files?
EDIT:
I followed the same folder structure and build settings used in the XCode project of libzbar. I have managed to build the library but it's still failing while linking. I get the error: ld: duplicate symbol _OBJC_METACLASS for all the source files. I have double checked, there are no references to the original libzbar.a static library in the project or more than one occurrence of these source files. If I remove the references for them, the project builds fine, but then fails whenever any symbol from the library is referenced. I think I am still missing something!!
I have solved this problem finally. Here are the steps that I did:
1) Copied the source files of the project to my project.
2) Removed the dependency of libzbar.a from my project.
3) Added the path to the folder containing the source and headers to the Header Search Paths build setting of the project.
4)Added the following user defined build setting to the project:
EXCLUDE_SOURCE_FILE_NAMES
GCC_MODEL_TUNING
PREBINDING and
USE_HEADERMAP
You should create the static library your self from the source code then add the output static library to your project, or link the projects together and force a build of the static library before your project is build.
After downloading the zip file from the default Mercurial repository and opening the file in xCode, click on the "EmbedReader" part of the target selection drop down box and switch to "zBarSDK"
Once you switch to the zBarSDK, just build from the product menu and you should have your static library file....
I used ZXing lib before and it integrated well. It was included as a project and main project has target dependency to build it before main project. I edited it's sources for my needs and have no problems working with it.
I used this tutorial. It can be helpful for your needs too.

NSClassFromString loading class from a library

For somewhat complex reasons, I'm needing to access a class from a library I'm writing externally via NSClassFromString. I've tested the method (NSClassFromString) on other libraries and it works with otherwise hidden/internal classes, but it won't work on mine. I build the library as a static library with the -ObjC flag, and I build the project with -ObjC as well. What do I need to do to get the library class to register properly with the lib so I can access it externally?
To be a bit more specific, I'm building a library with associated submodules. The user can add/remove submodules as needed, and I need the main lib to compile and run if they are missing, hence NSClassFromString on submodule classes and fail gracefully if they don't exist. I'm compiling the submodules into individual .a files.

Building a static library for iOS

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-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. 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...

How to build universal static library that works for os3.x and os4.x

Hi I'm trying to create a static library that can added to any ios project, but I can only get it to work such that if I build the library in ios3, it'll work for ios3 projects but not ios4 and vice versa.
The errors I get are:
Undefined symbols:
".objc_class_name_UIImage", referenced from:
literal-pointer#_OBJC#_cls_refs#UIImage in Test3-Release.a(TestViewController.o)
".objc_class_name_NSNotificationCenter", referenced from:
literal-pointer#_OBJC#_cls_refs#NSNotificationCenter in Test3-Release.a(Test.o)
So it looks like it's not finding Foundation and UIKit frameworks for the library?
Here's what I've done so far:
I have 2 projects: 1 is a library project with a library build target. The other is a Test Project that tries to use the library built in the first library.
1) Create a project with a static library target and added all of the implementation files
2) Added libraries like UIKit, Foundation, etc to the "Link Binary with Libraries folder and Set all the linked libraries to have a weak type in my library target.
3) Built the library, added it to my test project, along with my header files.
4) In my test project, I set other linker flags to -ObjC -all_load for all build configurations
When I compile it gives me a bunch of errors as if I didn't include any frameworks.
Anyone have any ideas on what I should do?
Hint (Maybe?)
I also noticed that adding any frameworks to the "Link Binary with Libraries" folder in my library target doesn't seem to do anything. I added CoreLocation to that folder, but when I try to compile in my Test Project it won't compile until I add CoreLocation to my Test Project Frameworks folder.
your dependent project (that uses static library) hassn't linked Framewrok libraries.
Just add to dependent project frameworks (uikIt,Foundation, etc) all will work fine.