bundle dylib with application - dylib

I'm running Xcode 4.5 and MacOS 10.7.4 and trying to create a MacOS app for local distribution.
I have a dylib from a 3rd party USB hardware vendor. Rather than drop this into /usr/lib, I wanted to bundle this with the app. I have tried all of the methods mentioned here that I could find:
Creating a Cocoa Library target, and using a copy build phase, setting paths with #rpath and #executable_path and #loader_path ...
Here's what I ran into:
I can get the target app to build to compile and run if the dylib is copied into the same directory as the target app (by setting destination to "Products Directory"), however this only works while the app is running within Xcode. If I run the app from the finder it still looks for the dylib at /usr/lib.
A caveat when changing the destination setting: any files copied to a location in the previous build are not deleted when you make a change a build again. This tricked me into thinking a few times that I had a solution when I didn't.
"Library search paths" appears to work as expected when linking, but setting "Dynamic Library Install Name" and "Runpath search paths" don't appear to stop the code from looking in /usr/lib only at run time. They don't seem to have any effect at all.
So, why would setting those path variables have no effect, and how can I set the run time search path?

Related

.app file not working in other MAC system

I have created a MAC application with libraries 'libmysqlclient.a' and 'libmysqlclient.18.dylib' with Objective-C language in Xcode 6.3.1 in OSX Yosemite 10.10.3. Its working fine when running through Xcode. And I also archived the .app file to install the app in my MAC, its also working fine. But when i tried to install it in another mac, app crashed and shows the message
"dyld: Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/developer/Documents/UntitledFolder/UserName/SampleApp.app/Contents/MacOS/SampleApp Reason: image not found".
From this message i understand that the particular MAC does not have “libmysqlclient.18.dylib”. So, here my question is "Is it mandatory that each MAC should have the library to install and run the application?". Can anyone give me the solution for this with detailed format of creating the .app file and installing it in other MAC systems.
Thanks in Advance.
You have included both a static (.a) and a dynamic (.dylib) library with your app. that do the same thing. A static library compiles into your program, making it larger. A dynamic library ships with your app. or is already install on your target system. If you ship it with your app., it should be in the Frameworks folder of your app. (you create this folder in Build Phases, Copy File). Use install_name_tool -id to set the library install name to #executable_path\..\Frameworks and also in Build Settings, set Runpath Search Paths to the same.

Xcode: how to build a static library project correctly?

This question will be easy for Xcode pros but for a MonoTouch developer it seems to be impossible to resolve. :-)
I'm using Xcode 4.5 and I want to target iOS 5.1 and above and iOS Simulator 5.1 and above.
I have a a library project here and it is coming with a prebuilt binary named "DemoLib" (no extension and it is 11MB in size). The library is a fat lib for Simulator and iOS 5.1+.
I can use that library without any problem.
However if I try to build the library myself, I end up with a "DemoLib.a" file (notice the extension and the size of 30MB). How can I get the same build result? What is a .a file compared to the file without extension?
I tried to build the project "for running", and "for archiving" in Xcode. Both results in the same 30MB .a file.
I was expecting some dropdown in Xcode where one could select "DEBUG" or "RELEASE" build and the latter one would create the smaller lib.
Of course I could never tell without seeing the framework's project file. Having said that, there is an excellent guide to creating and compiling iOS frameworks here: https://github.com/jverkoey/iOS-Framework
Using the above guide, you should be able to recreate your framework's project from scratch, add the files you have to it, and properly compile it.
Hope this helps! :)
Did it come with a Makefile? Create a new target, set the build settings of the target to what's in the Makefile, then set your project to depend on that new target.
A file with the .a is a static library, which means it depends on nothing external and all the code it needs is compiled inside it. I think no extension generally implies dynamic library, which means it'll depend on some dependencies being present on your system to link against. Maybe that's why the .a is so much bigger. I think Xcode will build static by default because iOS does not allow the use of dynamic libraries.
The dropdown for what to build is in your scheme. Command+shift+< to view your scheme. Within the scheme you can edit which environment each method of building will use.

FreeImage library not found

Installed FreeImage through MacPorts. Everything looked to be OK, but when I builded my app and tried to launch on other computer where is no MacPorts and no FreeImage installed it says
dyld: Library not loaded: /opt/local/lib/libfreeimage.3.dylib
Referenced from: /Users/development/Library/Developer/Xcode/DerivedData/freeimage-dxsornyaxqlkyubqwsrlkgszvxhy/Build/Products/Debug/freeimage.app/Contents/MacOS/freeimage
Reason: image not found
Shouldn't it copy library files together with my project? I added them to my project's build phases "Copy files" list. They are being copied to my app's bundle. But when I try to link them, I get same error. I don't know why but app is still looking for library in /opt/local/lib. How can I fix it so that I could use FreeImage at my project and run it at any computer?
When you install through MacPorts the library is installed in /opt/local/lib, not in your project path. Even if you copy the whole project, the *dylib libraries won't be copied because they are usually in /opt/local/lib.
I believe you have two options here: install FreeImage in every computer that you want to run your application, or copy the libfreeimage.3.dylib to the same folder where your binnary is and, if both systems are similar, that should work. If the two computers are different in terms of operating system version, hardware architecture, etc... then probably the .dylib that you have won't be compatible for the other computer.
Another thing you might want to consider is to modify your DYLD_LIBRARY_PATH variable, which specifies the paths in which the OS will look for libraries when linking. See this answer for more information.

Linking to library

I installed ImageMagick through MacPorts. So all library files are in /opt/local/lib and headers in /opt/local/include/ImageMagick. It works OK on my mac. In xCode Build Settings - > Search Paths everything looks to be set OK.
Added library files to Linked Frameworks and Libraries
When I build my app it looks to be working. But when I try to run builded app on other computer where ImageMagick is not installed there comes this error message:
How can I fix it to make users to be able use my app without needing to additionally install ImageMagick and so on? How to link it that needed library files would come with my app (in project bundle)?
Af of now your linking library is referred from /opt/local/lib/ ---
Solution for your issue:
Make sure where ever app is installed suport library is installed to right location
Carry the dynamic library with app bundle and refere the dyld from the app bundle which will be relative to app bundle launch path.
Update: If you are looking for the second option --- With this option your library will be placed inside your app bundle ... so app can refer the library from the app bundle.
The precompiled dynamic library can be carried with the application -- in xCode --> Go to Build Phases for the target --> Build Phase (copy files) ... this will make sure your dynamic library is copied to into your app bundle ...
Update “install name” inside each dynamic library --- You can use 'otool' command to know present install path of your precompiled library and you can precompiled library install path using'install_name_tool' command in your terminal.
No support for it from ImageMagick forum, no support from StackOverflow, so I guess its impossible...

Loading Growl in my Mac app: Unable to read symbols

I am trying to load Growl so I can use it in my Mac app, but I keep getting this error:
warning: Unable to read symbols for #executable_path/../Frameworks/Growl.framework/Versions/A/Growl (file not found)
warning: Unable to read symbols from "Growl" (not yet mapped into memory).
What does this mean and how can I fix this problem?
I guess there is a step I missed. Don't forget to do these steps:
Download the Growl framework from the Downloads page.
Copy the Growl framework to your application's project folder (or any subdirectory of it).
Add the Growl framework to your project, making sure that all the relevant target checkboxes are checked. The header files in the framework use UTF-8 encoding.
Add a Copy Files phase to your application's target (App target > Build Phases > Add Build Phase).
Get Info on the Copy Files phase.
Set the destination to “Frameworks”, with no subpath (clear the field).
Drag the framework from the group tree into the Copy Files phase.
From now on, your application will compile and link using the Growl framework inside its bundle.
Make sure you have the latest version of Growl installed on your machine, as well as the latest framework (build the Growl framework project that your app is using).