Copying dynamic library (.dylib) into a framework (.framework) - objective-c

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.

Related

Changes in local framework are not updated in my project

I'm actually using an internal framework in one of my projects. Now I need to modify some of the code of that framework, however, it looks like the changes are no recognised at all by the project that is using that framework.
After committing some changes in the framework, build it and re-import it in the project and debug them, I can see that lines that I added are not executed at all.
I know this because when I add a breakpoint in the framework in one of the new lines, these are never executed as if they didn't exist.
I've tried to remove the framework from my project and add it again by following the steps of these Stackoverflow answer
I expected that my changes in my framework are recognized/syncronised in the project as they use to do.
Maybe I'm doing something wrong, so it would be really helpful your ideas.
I found that it's necessary to follow the next steps strictly delete to don't have the same problem as I was.
Launch the framework project.
Assign the build type to a generic iOS device. Be sure all the classes are assigned to the Target.
Press the play (build) button.
The framework will appear on your desktop.
In the project that is going to use that framework, be sure to remove all the references related to the previous framework version, then delete it from the folder too.
Add the new framework version to its folder in the project.
Assign the references:
Drag the framework that has just been moved to the project, to the framework folder in Xcode.
Drag the framework, that has just been moved to the project, to Linked Frameworks and Libraries.
This worked for me, so maybe this is helpful for someone.

ASP.NET 5 and Build Action

I have a Web Site and Class Library built with ASP.NET 5. The Class Library depends on an set of external files (XML, EXEs, etc.). Those dependencies are added as part of the project and visible in the Solution Explorer of Visual Studio.
My Web Site has a dependency on the Class Library. When I build the Web Site, I would expect the dependencies of the Class Library to be copied to the Web Site, but they aren't.
The Build Action (Copy always, Copy if changed) appears to be gone with ASP.NET 5. How do I make sure that dependencies other then the DLL of the Class Library itself gets copied to the Web Site project?
First thing first, they won't be in src/yourProject/bin/Debug. Those have been moved to the artifacts folder.
Also, your project by default will not output DLLs. This is mainly due to performance reason but if you need your DLL to publish your application, check your project properties. In the Build section you should have an option called Produce outputs on build. Tick that and bingo.
You have your dlls. Most of the time (aka: while coding), you won't need them since they will always be recompiled in memory.
You need to manually add a pre/post build step in project.json

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.

Build Cocoa application Bundle with private dylib/framework

I use xcode 4 to build a cocoa application with a private dylib/framework.
In my development Mac, I put the dylib in the /usr/local/lib directory, and drag it into the project.
The app is compiled and runs perfect on my computer.
To distribute this app to the other Mac, I create a copy Files building phase, and say "copy that dylib to Frameworks directory".
The application is built successfully, and I indeed see the dylib is copied to the Frameworks directory in the app bundle.
The problem is when I run this app in another regular Mac, which does not have this dylib installed. I get an error saying:
dyld: Library not loaded: /usr/local/lib/mylib.dylib
The issue comes from the fact that you copy the framework into the app bundle, so it is available at a location like:
<you_app_path>/Contents/Frameworks
but you try to load it from /usr/local/lib where it is not available on you deployment machine. From Apple Framework Programming Guide:
To embed a framework in an application, there are several steps you must take:
You must configure the build phases of your application target to put the framework in the correct location.
You must configure the framework target’s installation directory, which tells the framework where it will live.
You must configure the application target so that it references the framework in its installation directory.
Now, you say that the build phase is ok; I assume also that you sent the application target build setting correctly. What is left is configuring the framework target’s installation directory.
If you did not build the framework yourself, you should be able to fix this by changing the framework install path so that it is defined relative to the loader (your app), to something like: #loader_path/../Frameworks/ (or #executable_path/../Frameworks). You can do that by means of install_name_tool.
If you are compiling on your own the private framework, you can define its install location in Xcode build settings.

Frameworks for static libraries xcode

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.