.app file not working in other MAC system - osx-yosemite

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.

Related

What will happen if a framework get deleted from an app?

I was asked a question, what will happen when a framework is accidentally deleted from your device may be iphone or mac?
Whether your application crash or it will work without any error?
Please provide me answer with explainations.
You may get linking error. If framework folder is inside the application means its runtime linking.
OS X embeds an "install name" inside each dynamic library. This
install name is the path to where the library can be found when dyld
needs to load it. When you build an application that links against a
dynamic library, this install name is copied into the application
binary. When the application runs, the copied install name is then
used to locate the library or framework.
$ otool -D /Applications/Google\ Drive.app/Contents/Frameworks/Python.framework/Versions/2.6/Python
/Applications/Google Drive.app/Contents/Frameworks/Python.framework/Versions/2.6/Python:
#executable_path/../Frameworks/Python.framework/Versions/2.6/Python
so if you will delete Frameworks folder you will get Dyld Error.
Dyld Error Message:
Library not loaded: #loader_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle
Referenced from: /Applications/Transmission.app/Contents/MacOS/Transmission
Reason: image not found
If a framework is deleted, only software linking to that framework would be affected.
If it is a system framework, expect your system to start failing.
If it is a 3rd party framework, it should be limited in scope of impact.
If it is in your app bundle, and your app is code-signed, the removal of the bundled framework should prevent your app from launching.
It depends on if the application needs access to the framework you have removed.
If you application requires the framework then it will not compile.
If you dont need it, it will just compile like normal.

Linker error for imported header file Xcode 4.5

I have downloaded a header file and static library file (.a file) from the internet. They are provided by the wireless printer which i bought for my iphone and trying to make print functionality working in my app. The problem is when I run the sample app provided by them to test printer, I get the following linker error...Obviously the app was designed in the previous versions of Xcode and Im using Xcode 4.5. Much appreciated if someone could Guide me..
If you are building an iOS project and it's using the i386 architecture, then you must be building for the simulator. What happens when you build for an actual iOS device?
It's possible that the library was compiled only for the processor architectures for real iOS devices, typically armv6, armv7, or armv7s. You can use the file command in Terminal to see what architectures are in the .a library file.
Check these answers Symbols not found for architecture i386? and symbols not found.
Check your project-> build phases -> Link Binary With Libraries whether there is libwspr240.a file is there or not.
Remove libwspr240.a file and then readd it using
Project --> Build Phases --> Link Binary with Libraries click '+' button to add.
Then Clean and Build the project

bundle dylib with application

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?

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