xCode and ImageMagick not working? Linking to project bundle - xcode

I made project with ImageMagick included. I installed it through macPorts, linked libraries and headers to my project. Everything worked. But when I try to launch my builded app on other computer, where ImageMagick is not installed, it doesn't even opens my app. Says that Os X version is incompatible. If I install ImageMagick to that computer, then app works OK. What should I do to make it working on computers where users does't have ImageMagick? I guess I have somehow to include headers and libraries to my project bundle. But how to do it in correct way to get working? I tried to copy headers and libraries to my project's bundle but then when I try to build it it says that Magick++.h is not found. Can somebody help me?
I added ImageMagick files from where macports installed it (/opt/local/lib/ and /opt/local/include) to my created folder named ImageMagick, then moved that folder to my project and added ImageMagick/** to Library Search Paths and Header Search Paths. Then removed ImageMagick through macports. Project builds successfully, but doesn't runs. It shows error in console:
dyld: Library not loaded: /opt/local/lib/libMagick++.5.dylib
Referenced from: /Users/development/Library/Developer/Xcode/DerivedData/OGL-cahltqazoqxhrthkxztsqyvvodge/Build/Products/Debug/OGL.app/Contents/MacOS/OGL
Reason: image not found
(lldb)
Libs added to Linked Frameworks and Libraries list is in my app's folder and added to my project. Why it searches for it in /opt/local/lib?

Related

Qt Project Dyld Error Setting rpath

I have a Qt project and I need to include some libraries
I have this in my .pro file:
QT += webengine
I can build and run it fine on my Mac but if I try to send the .app to someone else and they run it, there is this error:
Dyld Error Message:
Library not loaded: #rpath/QtWebEngine.framework/Versions/5/QtWebEngine
Referenced from: /path/myApp.app/Contents/MacOS/myApp
Reason: image not found
I have the QtWebEngine.framework and its corresponding QtWebEngine.framework.dSYM file in my directory:
Users/myUsername/Qt/5.11.0/clang_64/lib
I also have the .framework in my directory:
Library/Frameworks
In the editor, I looked at Projects > Desktop Qt 5.11.0 clang 64bit2 > Run > Run Environment, and I found that the DYLD_FRAMEWORK_PATH points to where the .framework file is located. Same for DYLD_LIBRARY_PATH.
This is confusing me because it works on my Mac but not on others. It also seems like the paths are all in order. I have tried using other suggestions on this website but they do not seem to work for me or maybe I just did them wrong. Maybe someone could help me?
Update:
If I need to add the .pak resource files to my deployment, how can I do this?

What is a .framework file and how can I get it?

I'm attempting to use OpenCV in Xcode. I've installed OpenCV 2.4.12 using Homebrew. The associated files are located in /usr/local/Cellar/opencv.
In the documentation I am instructed to add "opencv2.framework" to my project as a binary library. There is no opencv2.framework file anywhere in my opencv directory.
Do I have to make the .framework file or something?
Explore /System/Library/Frameworks for examples on your OS X system. These are bundles containing headers and the compiled framework binaries. If you don't have a .framework directory in the OpenCV resources that you installed, perhaps you installed the source code and you have to build the framework.

Xcode can run my program, but I can't run it manually

I have a project with a dynamic library and an executable that links against it. I can successfully start it with Xcode, but when I try to run it from the command line, dyld complains about the library not being in the install path:
$ /Users/USER/Library/Developer/Xcode/DerivedData/PROJECT/Build/Products/Debug/EXECUTABLE
dyld: Library not loaded: /usr/local/lib/libMyLib.dylib
Referenced from: /Users/USER/Library/Developer/Xcode/DerivedData/PROJECT/Build/Products/Debug/EXECUTABLE
Reason: image not found
Trace/BPT trap: 5
The problem is quite clear: the library isn't in its advertised install path. However, I don't really want to deploy it there, and besides, Xcode still manages to start my program.
How can I run my program without installing the library in /usr/local/lib?
If you're relying on a dylib, then it needs to be installed in the appropriate location.
Using a framework might help, as you can package it in your application, using #executable_path...
But then, of course, you won't be able to share it across different applications.
So basically, you need to tell Xcode to install your dynamic library.
This can be done in your build settings, in the Deployment section.
Mainly, Deployment location, Installation directory, Skip install, etc...
Note that you can also do this for frameworks, installing them into /Library/Frameworks/

Deploying Qt Frameworks with Mac app and usage of otool

I have a problem deploying Qt frameworks with my Mac app, and I hope some will have a clue why I get this error, when I run the app on clean Mac, i.e. not a developer Mac.
OS: 10.7 .2 and using XCode
Error msg:
Library not loaded: #loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Clearly something is wrong since the QtXml is referenced from /../Frameworks/../Frameworks, which doesn’t exists.
This is the set up: I have a dylib that uses QtCore and QtXml (not by my choosing, but for now I need those two frameworks), the dylib is used in a NSBundle, which is loaded by the main app, the bundle is located in the resource folder. The dylib is moved by Copy Files Build Phase to the folder Contents/Frameworks and with otool the install_name is set to (as stated by http://doc.qt.digia.com/4.3/deployment-mac.html):
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
#loader_path/../Frameworks/QtXml.framework/Versions/4/QtXml
then the Qt frameworks are moved to Contents/Frameworks and the install_name of the is set to:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
and for the QtXml
#executable_path/../Frameworks/QtXml.framework/Versions/4/QtXml
with reference to QtCore:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Now when I run the app on the developer mac it clearly works since Qt is installed, but when moved to a clean mac I get the error msg, readable in the Console app.
I’ve tried to change the executable_path to loader_path, but this didn’t work.
I have no idea what I’m doing wrong or why it won't for, and have not been able to find anything on Google, of course I could be looking at the wrong places. Any ideas how to fix this problem?
This is the entire error message:
MainApp: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle
“Library” couldn’t be loaded because it is damaged or missing
necessary resources."
(dlopen_preflight(/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/
Contents/MacOS/Library): Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from: /Users/ someUser /Downloads/
MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found) UserInfo=0x107c5d5d0
{NSLocalizedFailureReason=The bundle is damaged or missing necessary
resources., NSLocalizedRecoverySuggestion=Try reinstalling the
bundle.,
NSFilePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library,
NSDebugDescription=dlopen_preflight(/Users/someUser
/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library):
Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:
/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found,
NSBundlePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle,
NSLocalizedDescription=The bundle “Library” couldn’t be loaded because
it is damaged or missing necessary resources.}
On the development mac everything works because the Qt libraries are installed. On any mac you ship the app to, though, this likely won't be the case. The Qt suite comes with a tool called macdeployqt to fix this. So in a terminal, after you've compiled your application, do something like:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app
Note that it can also be used to create a .dmg file for shipping everything together:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app -dmg
Once you've done that, the .app directory or .dmg file can be given to someone else without Qt installed to use and run as they normally would.
The one caveat is that the next time you try to run it on your developer machine, it may complain about multiple shared libraries installed. So once you've copied it else where in order to distribute it, remove the entire .app directory and let qtcreator (or whatever) rebuild it.
UPDATE
As stated compiling QT to static libs is the way to go. With the release of Mavericks (10.9) we need to codesign frameworks as well (http://furbo.org/2013/10/17/code-signing-and-mavericks/), and with QT4.8.5 there are some issues (https://bugreports.qt-project.org/browse/QTBUG-32896). Even with suggested fixes I still had some issues when running the app on a clean machine. Therefore, I ended up with compiling Qt5.2 to staticlibs, link them in the app, and codesign them.
OLD
Problem sovled, I moved the Qt-frameworks into the app bundle in Contents/Frameworks and with otool set the path to #executable_path/../Frameworks, i.e. moved it out of my library bundle. Yes the solution is simple, but I'm still not sure why the library executable couldn't find the frameworks when using #loader_path.
The best solution would probably be to use a static library and not wrap it in a bundle...you learn everyday ;)

Linking Macports libraries to XCode application

I'm trying to distribute my app's dependencies with the app.
I've got the macports packages librsvg, boost, and cairo installed 64-bit-only on my Snow Leopard system. When I create an .app bundle of my program, it does not work on machines without macports and the relevant libraries installed because they are not included with the app, which searches for the libraries in /opt.
I have tried the --static flag for static linking, but that caused libcrt0 errors.
What's the best method for linking MacPorts libraries and their dependencies to an OSX application suitable for lone distribution?
You'll want to copy the libraries into your application bundle, using a Copy Files Build Phase. dylibs should be put in the Frameworks directory in the app bundle. You'll also have to add the libraries to your Xcode project.
Try using py2app to create a stand-alone app.
I had to just do this for jsoncpp. What I did was I went to linker settings under the project > Build Phases > Link Binary With Libraries then used the add other to go to my library's path and add the library from the folder which would be under opt/local/lib in the default setup for macport
getting the header files was a bit more complicated. In this case I had ended up going to usr/Include finding the file/folder with the headers, copying it into my project and in the cpp file I added the include line with quotation marks ("")
e.g., moved /usr/Include/json directory into the RestTemplate Project folder using copy. then added to main.cpp
#include "json/json.h"

Resources