Library Project Reference in Xcode - iphone

I know something like this is already asked many times on SO, but I've tried everything (been at this for three hours now) and I still didn't find a solution. I'm quite new to xCode and I'm starting to work on a project that was originally created by somebody else.
So, I have a library project in my xcode (XS2Library) and now I would like to reference to that library in my other project (WaarBenJij). Building the Library succeeds and I reference to it by adding the LibXS2Library.a to the Project target's "Link Binary With Libraries".
Xcode doesn't give me any errors, so it looks like the library project is referenced appropriately. However, when I try to build my project I get the error that a class that resides in my library project cannot be found ("'XS2URLLoader.h' file not found").
Can anybody steer me in the right direction, maybe?

There's a sensible difference between the .a file, which is needed for linkage and contains the library source, and the .h file, which is needed to compile (and preprocess) and which contains the functions and classes declarations.
Here you included the .a file, which is required for a later step, but to use the library you also need to import the required .h files into your project.
The easier way is to simply put them in your project.
Or you can add the whole library as a subproject and as a dependency.

Related

Wrap a C++ library in Swift code, compile as a Cocoa Touch framework

I have a C++ library that is full of warts and weird features, and I want to make it much easier to use (and reuse) in a Swift project. So I intend to wrap this C++ library in some Swift code, then make it available as a Cocoa Touch framework.
I've added both my (fat) .a file and the required .h files to my project, then added the .a to the "Link Binary with Libraries" section of Build Phases, and added the main .h file to the Project section of the Headers build phase. But the build fails with:
Library not found for -lMyLib
I'm obviously missing something here - I'm guessing maybe I need to adjust the Framework Search Path and/or Header Search Path? Or am I missing something more fundamental? My desired end result is a .framework another developer can pull into their Swift project without having to do any other build setting tweaks.
You're probably looking for "Library Search Paths" (LIBRARY_SEARCH_PATHS). You may need to add to "Header Search Paths (HEADER_SEARCH_PATHS) as well, depending on your setup. In this case, you shouldn't have to add anything to the Framework search paths, since you are not dealing with a Framework.
(As an aside, you are likely going to find that you have to wrap your C++ library in Objective-C++ code to expose the functionality to Swift.)

how do I reference a separate project in xcode 4?

How do I reference another project which has code I wish to leverage in XCode 4. In particular I'm trying to make use of the NSDate extensions from here.
Some notes:
I was assuming I should probably reference rather than trying build a framework
I tried copying the existing "Hello World" xcode project file across into my project, however this didn't seem to work
Do I need to create a new "Target" based on "coco touch static library" option?
Then would I need to Edit the current Product Scheme so that when I build the new target would build
What do I need to do on my project side exactly - should going Add Files, and choosing the extensions Xcode Project File be enough?
thanks
I was assuming I should probably reference rather than trying build a framework
yes, reference and link with it, unless you need only a bit of it. at this stage, separating the bits you want may be an advanced topic (depends on the lib's layout/depends as well). you should prefer to reference and link because it will normally minimize your maintenance time, especially if you use it in multiple projects.
I tried copying the existing "Hello World" xcode project file across into my project, however this didn't seem to work
you don't create a project, you add the library's xcode project to your app or library, set the lib as a dependency, add the library to your search paths if needed, then link with the library.
Do I need to create a new "Target" based on "coco touch static library" option?
no
Then would I need to Edit the current Product Scheme so that when I build the new target would build
no. you configure it as a dependency. you may need to alter the lib's build settings if there is a major conflict, which the linker or compiler would point out.
What do I need to do on my project side exactly - should going Add Files, and choosing the extensions Xcode Project File be enough?
start with the process outlined above.
There is no reason to bring in an actually project. Either you can bring in the source files themselves and you could even use the same exact files instead of copying them if you want. However, if you have more than just a few files, and you don't think you will be changing the code much, then creating a static library would probably be the best option.

XCode: Linking projects inquiry

I have 2 projects and I want to use in the first project, a class (i.e. view controller) of the second. Instead of importing all the files of the second project in the first one, is there a way to link it like a framework or library?
I tried the following unsuccessfully:
Dragged-dropped SecondProject.xcodeproj and checked SecondProject.app as a target
Added it as a dependency project in the first project dependencies
Pointed to the header files by adding in the "Header Search Paths" a path pointing to the second project which I copied in a subfolder of the first project.
When I include "SecondProjectViewController.h" I get no errors but when I try to instantiate it I get the "OBJ C referenced from" error.
Any help is deeply needed and appreciated! =)
F.
As an experienced developer I would suggest not sharing code this way across projects. The simple reason is that changes in one project will then directly effect other projects, often rendering them un-compilable. For example, if you share a controller class and decide to implement a change with a new import, then any project that uses that class will be broken until you open then in xcode and ensure that the imported class is available.
A better method is to compile your first project as a static library or framework. I'd also recommend ensuring that it is version some way. For example, in my projects I create static frameworks and store them in a directory called "v0.0.1", "v0.0.2" etc.
The framework can then be dragged and dropped into a second project to use it. The second project then refers to it via the directory path. The advantage of doing this is that if I then change the first project, the second one if not effected by the changes until I choose to update the frameworks path.
Sharing files between projects will work for small cases, that being 2 or 4 projects, but once you have more than that it rapidly becomes un-manageable.
You have only a few steps to go:
4) in First project, click the disclosure triangle in the Groups and Files section for the Second Project reference. this will display the targets of Second Project.
5) Drag the target reference (e.g., static library) from Second Project to the target in First Project's link phase.
That should clear up all the linker errors for the symbols which exist in Second Project's library. Of course, you'll have to remove those sources (based in second Second) which are compiled and linked from First.
Managing static libraries for huge codebases is dead easy this way (although I prefer the build up to the minute (as well as several build variants), and don't reference archived binaries as Derek does). Learning to minimize changes which break builds takes time to learn. dynamic libraries are a bit different - depending on their distribution, you may want to version (as Derek outlined). It's good to share, but you should put the shared exported symbols in a library, which is a dependency of both apps. Just be careful not to add too much unnecessary objc symbols to the library - objc symbols and their references cannot be stripped from the final executable and they will cause runtime collisions if they appear in two images (dylib, app, static lib) within the same process.
You can add the view controller's files to your 1st project regardless of where they are on disk -- the project will make a reference to their location.

objc_class$____ error

For my application i need to work with calendar.
http://blog.webscale.co.in/?p=244 from this link i downloaded required stuff.....
related to calendar.... now i need to import it into my application.
Even i added all the required framework in my application. its showing me error...
"_OBJC_CLASS_$_CheckmarkTile", referenced from:
Any one help me out. What to do..
This _OBJC_CLASS_$_ Error comes if you dont include the framework for that corresponding Object class. In your case this CheckmarkTile.
If you have included this calendar component in your project. Then rightclick frameworks group in xcode add Existing Frameworks. The Select AddOther and include the build file of that calendar project. Now Clean Build and run.
Or Just try this
Just include the ChemarkTile .h and .m files into your project and then clean build
Make sure it's added to your target to compile. As stated above...
Just include the ChemarkTile .h and .m files into your project and then clean build

Add external project to my iphone app in xcode

Just starting to poke around iPhone development. I am trying to add an external project/library to mine (specifically the ASIHTTPRequest, http://allseeing-i.com/ASIHTTPRequest/).
I am at a bit of a loss as to how I go about actually adding this dependency to my project. I come from a Visual Studio/C# world, and in Visual Studio I know I would "Add Existing Project" to my solution file and then add a reference to the new project to my own. Or, alternatively, reference the DLL directly if it is already built.
The ASIHttpRequest project is on GitHub, and provides full source code. I just don't have any idea about how to actually get this dependency into my own project. I tried "Project -> Add To Project", and just selected the folder ASIHTTPRequest extracted out into. I see it as a sub-folder to my project now... but get a ton of build errors. I removed everything but the .h and .m files from this subfolder, and now I don't get any build errors from those resources anymore, but trying to reference a ASIHTTPRequest object in my own project gives "undeclared" errors.
Am I missing something here? Can I not of these .h and .m files in subfolders?
You're on the right track. You just need to #import the ASIHTTPRequest header in the file where you want to use it. You do have to make sure you've met all the dependencies specified on the ASI site, but once you've done that, everything should work right by just doing an import like you've described. Once all that is set and everything is compiled, add this:
#import "ASIHTTPRequest.h"
to the top of the file where you want to use the library.