OSX terminal app, fails to load dylib file - macos

I have created a dylib file. Successfully added it to one Terminal(Console based app through Xcode). When I run the app through Xcode they dylib is loaded and all the methods inside it works.
The issue is when I run the Consols App (Unix Executable) it fails to find the dylib and throws the following error.
DS-Anoopkumar-v:~ anoopvaidya$ /Users/anoopvaidya/Library/Developer/Xcode/DerivedData/Worker-dfytfqadwmzqmvesrzqeartqcggx/Build/Products/Debug/Worker; exit; dyld: Library not loaded: #executable_path/../libDownloader.dyli
Referenced from: /Users/anoopvaidya/Library/Developer/Xcode/DerivedData/Worker-dfytfqadwmzqmvesrzqeartqcggx/Build/Products/Debug/Worker
Reason: image not found Trace/BPT trap: 5 logout
[Process completed]
Please tell me what I am missing here, any help will be highly appreciated.

In Build Setting's "Dynamic Library Install Name" I replaced "#executable_path/.../Framework/libILDownloader.dylib" with "#executable_path/libILDownloader.dylib" and it worked.
Thanks to this answer How to use dylib in Mac OS X (C++), that helped me to understand

Related

Xcode - dyld: Library not loaded error

I'm new to MAC and Xcode since I'm a Windows user and I'm really lost. I finally managed to port my game from Windows to MAC and it works in simulator and all but when I launch the executable I get the next error.
dyld: Library not loaded: /opt/local/lib/libSOIL.dylib
Referenced from: /Users/myUser/Documents/Cotc/CourierOfTheCrypts/DerivedData/CourierOfTheCrypts/Build/Products/Release/CourierOfTheCrypts
Reason: image not found
Trace/BPT trap: 5
logout
I've read a lot of topics about the error but I still don't have a clue about it and how to solve it. All the libraries are copied to the executable folder.
If you need more information please let me know, every bit of help is more than welcome!
EDIT: It turns out /opt/... folder does't exist at all...
The solution to my problem is, to execute the following script for each library:
install_name_tool -id #executable_path/libSOIL.dylib "$CONFIGURATION_BUILD_DIR/libSOIL.dylib"
You enter the script in TARGET settings -> RunScript

dyld : Library not loaded - How to make xcode look for library in a path

I am attempting to run my xcode project and I get this error:
dyld: Library not loaded: libosgd.130.dylib
Referenced from: /Users/raj/MyApp-Build-XCODE/bin/Debug/MyApp2.app/Contents/MacOS/Myapp2
Reason: image not found
My project .xcodeproj was created using CMake. I know where this library is present. How can I tell xcode to look for it in a specific path.I am fairly new to xcode 7.Here is what I tried.
I went into the build settings of the project.Expanded "Linking". Then expanded "RunPath Search Paths". Then inside the debug row underneath my project column added the path to the library such as
~/Mypaths/lib/
However I am stilling getting this error when I run project. Any suggestions ?
I faced this problem while I was using Alamofire library
The following step solved it for me:

Gazebo on OSX 10.11 fails to start. Library "libOgreTerrain" missing

I followed the tutorial from the official guide in order to install Gazebo 6, on OSX 10.11.
But, when I try to run gazebo, I get the following error.
It doesn't find the libOgrePaging library.
$ gazebo
dyld: Library not loaded: #executable_path/../Components/libOgrePaging.1.7.4.dylib
Referenced from: /usr/local/lib/libOgreTerrain.1.7.4.dylib
Reason: image not found
Trace/BPT trap: 5
Is there a workaround for this problem?
Can I install manually this library?
Thank you very much for your time,
Kostas.
After some quest, I solve this issue by doing the following. In my case, I have two libs missing (libBulletDynamics.2.86.dylib and libOgrePaging.1.7.4.dylib), both installed but not linked.
To look for where are they:
find /usr/local/Cellar -name "libOgrePaging.1.7.4.dylib"
Add the containing lib to the end of ~/.bash_profile:
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/Cellar/bullet/2.86.1_1/lib:/usr/local/Cellar/ogre/1.7.4_2/lib:$DYLD_FALLBACK_LIBRARY_PATH
And source it
source ~/.bash_profile
Reference:
Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what's the dynamic library search algorithm with it?
dyld: Library not loaded ... Reason: Image not loaded
This is probably not the correct solution, but it seems to work for me so far.
Go to /usr/local/Cellar/gazebo6/6.60_2(or whatever version it is)/ and make a folder called Components.
After that, go to /usr/local/Cellar/ogre/1.7.4/lib and copy all of the contents into the components folder, and then gazebo should launch.

OBD-II Simulator on OS-X

Has somebody installed OBD-II simulator on mac? I tried downloading it from this site - http://icculus.org/obdgpslogger/obdsim.html for OS-X.
After installation and opening ObdGPSLogger, I can see GPS logger window and different parameter gauges. However, after selecting Logfile, and device there is nothing happening.
In the Raw output, below is the error displayed under StdErr:
Dyld: Library not loaded: /Users/chunky/gpsd//lib/libgps.18.dylib
Referenced from: /Applications/OBD GPS Logger.app/Contents/Resources/bin/obdgpslogger
Reason: image not found
Let me know if you guys know the cause
I had the same issue here, but I got it working on a Mac downloading the obdgpslogger-0.16.tar.gz version (in the Tarball section) from this link.
You need to navigate to the downloaded folder and then run the commands:
mkdir build
cd build
cmake ..
make
make install # optional

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 ;)

Resources