Frameworks for static libraries xcode - objective-c

I have just added a linked library to my project using the question here Process for linking static ObjC libraries in XCode and the document linked to in the answer.
I happen to know the library uses CoreData objects, like NSManagedObject, although in the library's xcode project the CoreData framework isn't added and it builds with no errors. However when I build my app it comes up with several errors such as:
Undefined symbols:
"_OBJC_CLASS_$_NSManagedObject", referenced from:
_OBJC_CLASS_$_AClass in library.a(AClass.o)
So seeing as all the errors mentioned CoreData objects, I added the CoreData framework to my app and it built successfully.
So now I tried remove CoreData framework from my app and added it the libraries project and them built both and it failed.
So why does it work when I have coredata added in my project but not in the libraries project, and only the library uses it?
(and why does the library build without needing the coredata framework on its own?)

The library is static. It is not a stand-alone piece of code, it must be linked.
Your application is linked, which means the linker resolves all the external dependencies and fills in the library functions' addresses in the final executable.
If you want to use a library that has a Core Data dependency in your application, you must link against Core Data.framework.
Adding a linking stage to a static library has no effect, since there is no linker involved in creating a static library, only a compiler (and an archiver).

Now, the problem can sometimes be avoided by using the new #import syntax in your libraries header file. The compiler will then automatically link against the used framework, even if you use a static library.

Related

Error after applying custom framework

First of all, I have built a custom universal framework successfully.
Inside the framework, I have references to other 3rd party library and framework. I believe when I link this custom framework to other project, I need to set up the reference for those 3rd party resources.
Now the problem is, when I link this "MyCustomFramework" to my project, it's having
:
undefined symbols for architecture armv7:
"_environ", referenced from:
_GenerateEntropicChaos in MyCustomFramework
I learned the error usually caused by library search path issue. Since this error is point to the Framework, so is it the current project path is wrong or the project that build this framework is wrong? It seems like all the 3rd party also having this undefined symbols issue.
Maybe it's reate to simulator or real machine, so try following:
first choose target to simulator and build your framework.
second choose target to real machin , build another framework
then link these two framework seprately to you project. and see what will happen.

Does dynamic libraries link other libraries for you?

I noticed how you don't have to link opengl32.lib by yourself when you use libraries such as SFML and I'm really wonder how that could be since I have to link opengl32 in my projects that are using my own multimedia library which is a static library? Is it simply because the SFML library is a dynamic library and opengl32 is linked in the SFML project?
This is not a question about SFML, it's rather a question about all DLLs in general.
Yes, DLLs can reference other DLLs, or statically compile them internally. To inspect external dependencies, Microsoft long ago developed a tool called Dependency Walker, in which you can drag a DLL or executable and see which DLLs it depends on (and thus are automatically loaded). The tool used to be shipped with Visual Studio by default, but you can now download it from here for free. That page kind of explains everything else about it.
If a dynamic library is using another dynamic library, it will automatically get loaded into the process, yes.

Cocoa Frameworks: Using one framework inside of another

I'm building a framework (main) which uses another framework (sub). Main framework will be used then in different apps.
The main framework target builds without errors. However, if I try to build an App which uses the main framework I receive an error -> Class in the main framework cannot find/import the sub framework...
How can I configure main framework so that it will find the sub framework?
As I understand you want to create one framework inside another. It is called "Umbrella framework" and it's not a good idea.
Documentations says:
Don't Create Umbrella Frameworks
While it is possible to create umbrella frameworks using Xcode, doing
so is unnecessary for most developers and is not recommended. Apple
uses umbrella frameworks to mask some of the interdependencies between
libraries in the operating system. In nearly all cases, you should be
able to include your code in a single, standard framework bundle.
Alternatively, if your code was sufficiently modular, you could create
multiple frameworks, but in that case, the dependencies between
modules would be minimal or nonexistent and should not warrant the
creation of an umbrella for them.
You can use one framework inside another, but both frameworks must be included to your app target and must be copied to /Contents/Frameworks/ directory of your app bundle. Also you must set Installation directory to #executable_path/../Frameworks for both frameworks.

Calling MonoTouch Library from Objective-C

I am using this article as a guide to call into a MonoTouch library from within an Objective-C application. We have an existing iPhone application and an existing c# library which we need to bring together. We have considered re-writing the iPhone app (Objective-C) in MonoTouch, but we do not have the time right now. We need a way to use our MonoTouch library from the iPhone/Objective-C app.
My problem is, the Xcode project generated by calling mtouch cannot be compiled. It cannot find the mono header files and the .s files referenced by the project are not found because they are instead named with a .6.s extension. Am I running mtouch incorrectly? If not, how can I tell the Xcode project where the mono header files are located so it can compile? Also, how can I set up the Objective-C code to call my MonoTouch library (the main.m file has some clues, but it does not appear to be straight-forward)?
Here are the type of errors:
error: mono/jit/jit.h: No such file or directory

Copying dynamic library (.dylib) into a framework (.framework)

I have two XCode projects: a framework and a client application.
My application depends on my framework and everything works fine with that — the framework is being recompiled everytime the app is, the projects build paths are set correctly, it's completely okay.
Now the framework started using 3rd party dylib file, and it's linked against the dylib.
I've even added a build phase to copy that library into the framework's resources dir.
When i'm trying to run the application, everything compiles correctly, then i get this:
dyld: Library not loaded: /usr/local/lib/libplplot.9.dylib
Referenced from: /Users/railsmaniac/Projects/Study/Calculus of >approximations/Builds/Debug/XNMaths.framework/Versions/A/XNMaths
Reason: image not found
How can i fix it?
Adding the library into client application's resources doesn't fix the problem.
I can just place the library into the required location, but i prefer to keep it IN the framework.
Is it possible?
It looks like your application is expecting the library to be found at a specific path on the system. If you are on OS 10.5+ you can use the new #rpath functionality to allow your application to link dynamically to your library.
See this post for further details. It also shows the "old" way of doing this.