dyld: Library not loaded, Reason: image not found - macos

I used gdb normally until this week. Now running gdb I see:
(gdb) r
Starting program: /Volumes/MyProg
dyld: Library not loaded: #rpath/libCore.so
Referenced from: /Volumes/MyProg
Reason: image not found
(gdb)
How to fix it?
I have:
OSX 10.9
GNU gdb (GDB) 7.6 installed with MacPorts
P.S.
I have reinstalled gdb and Xcode. This does not help.
I see a lot of questions about dyld issues, but obviously I lack experience with libraries on OSX, and they appears to be useless for me.
For example this topic: dyld issues library not loaded
But how to download library again?
Or this topic: Dyld: Library not loaded
But how to find out install name? What is #rpath?

I solved this issue with "Embedded Binaries" in the General project settings.

i have solved this issue by changing the following settings
Go to Project Setting Your_Target->General->Embedded Binaries-> Click on + button and add your library here

How I fixed it:
libCore.so is a library from ROOT framework, which MyProg uses.
If I understand correctly, the message Library not loaded: #rpath/libCore.so Referenced from: /Volumes/MyProg Reason: image not found means that linker found the library, but can't use it.
Root, during installation uses clang by default. Meanwhile as I prefer gcc and MyProg uses gcc.
I have reinstalled root with gcc compiler:
./configure --with-cxx=g++ --with-cc=gcc --with-ld=g++
I have recompiled MyProg.
and now I can debug it with gdb.

You can find more information about rpath here: link
So you need to point the path to your libCore.so, but honestly I have not faced with this library so I don't know where is it located.
You can check also this answer to understand what it is rpath: answer

For Xcode 11 or above, there is another simpler solution which worked for me if you are using Cocoapods.
In your Podfile, add use_frameworks! after your Target line like this -
target 'YourAppName' do
use_frameworks!
Basically it adds all your pods as a framework in your framework folder.

Related

Xcode Library not found for -lavutil.57.28.100

I try to make macOS GUI application with ffmpeg.
On project settings -> General -> Frameworks,Libraries..., I added the ffmpeg lib files
/opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib/libavutil.57.28.100.dylib.
I also add lib search path of /opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib
I still get error : Library not found for -lavutil.57.58.100.
I like to get more detail about error.
I think these possibility
not valid arm64 format.
linker expect x64 and arm64 binary. But the file has arm64 only.
Dependency of dylib is missing.
If someone knows solution or detail about this error, please let me know.
That file exist and valid arm64 Mach-O file.
file libavutil.57.28.100.dylib
libavutil.57.28.100.dylib: Mach-O 64-bit dynamically linked shared library arm64
Some tips that will help you to troubleshoot this issue.
Firstly, lldb expects an arm64 version of the lib if your main executable's architecture is arm64, a fat-universal version of the lib if your main executable's architecture is fat-universal.
So please check the main executable's architecture inside YOURAPP.app/Contents/MacOS. I'm taking IINA video player as an example:
lipo -i /Applications/IINA.app/Contents/MacOS/IINA
Secondly, it's not good to refer to a brew version of the binary. If the library's version on another machine mismatches with yours, your app will crash. It's ok that you copy the dylib file and copy it into your Xcode project. Then you can add the dylib file to the Frameworks, libraries, and Embedded Content section in Xcode. The below image shows an example of integrating ffmpeg libs into your project.
Alternatively, the ffmpeg-kit package is your friend. I have a simple showcase for you: Github
Finally, if you insist on using the brew version, please disable checking on code-signing for external libs: Project Settings > Signing & Capabilities > Hardened Runtime > Runtime Exceptions > Diable Library Validation
Xcode does not add library search path.
I add -L/opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib on "Other Linker Flags"

"Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib" with Xcode 8?

My project requires OpenSSL libraries crypto and ssl. After updating Xcode to 8.2.1, compiling my project fails.
In my project Build Settings, in Linking, I have -lssl -lcrypto -lxml2 that indicates to load those libraries. Going back to my app Build Settings, I add /usr/local/opt/openssl/lib/ in the Library Search Paths to tell Xcode where to look.
Hurray, it compiles, builds and run properly. Cool.
BUT
When launching the app on a different mac, the app crashes, with this linking error:
Dyld Error Message:
Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /Applications/MyApp.app/Contents/MacOS/MyApp
Reason: image not found
That means the app is trying to load the open ssl libraries that might not be present on that mac. There might be just an older version, or that folder might not exist at all? So that's definitely a no-solution.
Here lies my issue, I have no idea how to solve this problem.
Removing -lssl -lcrypto from the linking doesn't help, as the has errors during linking.
I guess I need a way to tell Xcode to look there when compiling only. Would that be possible?
If you don't wish to ship libraries and deal with making sure the linker can find them, you can link your code against a static library.
Using the code in this question as a linking example, I compiled with this command:
cc -I/opt/homebrew/Cellar/openssl#1.1/1.1.1q/include -o Link14 Link14.cpp /opt/homebrew/Cellar/openssl#1.1/1.1.1q/lib/libcrypto.a -lc++
This uses system libraries for most things, but the static version of libcrypto in libcrypto.a for the encryption. You can add multiple by placing them on the compile/link line.

/usr/lib/libstdc++.6.dylib: mach-o, but wrong architecture

I've just update my MAC OS Mountain Lion's compiler to gcc 4.8.1, the configure & install process is:
./configure --prefix=/usr
make
sudo make install
the GCC 4.8.1 was installed completely, but then I found I cannot open my Chrome, as well as several other programs. I've check the error report, the most important information is:
Dyld Error Message:
Library not loaded: /usr/lib/libstdc++.6.dylib
Referenced from: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Reason: no suitable image found. Did find:
/usr/lib/libstdc++.6.dylib: mach-o, but wrong architecture
/usr/lib/libstdc++.6.dylib: mach-o, but wrong architecture
So what should I do to solve this? Recompile GCC with proper architecture? But how to do this?
You have overwritten several system libraries with incompatible versions. You will need to reinstall Mac OS X.
Don't install software with --prefix=/usr. That prefix is reserved for software distributed with the operating system. Use /usr/local for software you install yourself. You may want to try Homebrew instead once you've reinstalled.
Since libstdc is deprecated and removed in iOS12, you need to update your dependencies to use libc++ or manually add libstdc. For manually adding refer this - answer

Cannot set deployment target below OSX 10.8 (Error: dyld: Library not loaded -- Reason: Incompatible library version)

I am trying to build and run an Cocoa-based OSX app. However, when I attempt to set the deployment target to anything other than 10.8, I get a runtime error when the app attempts to launch:
dyld: Library not loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices
Referenced from: /Users/chris/Library/Developer/Xcode/DerivedData/Build/Products/Release/MyApp.app/Contents/MacOS/MyApp
Reason: Incompatible library version: MyApp requires version 64.0.0 or later, but ApplicationServices provides version 1.0.0
As far as I can tell, there is nothing in my app that uses anything from the ApplicationServices.framework. I don't even know why it would attempt to load that library.
For reference, I'm using a few 3rd party frameworks, including Growl.framework (Growl 2.0), Sparkle.framework (Sparkle 1.5 b6), and MagicKit.framework (https://github.com/aidansteele/MagicKit)
Answering my own question (after several hours of investigation):
Apparently, by linking to CoreGraphics.framework in my Desktop app project, it caused a runtime load request for the 10.8 version of the ApplicationServices framework. Fortunately, I wasn't even using anything from CoreGraphics. Removing caused the dyld loading error to stop.
Make sure to have the ApplicationServices.framework added
to the Link Binary With Libraries Phase in your target's Build Phase tab.
I got this error by trying to use symbols in CoreGraphics and importing <CoreGraphics/CGGeometry.h> directly, instead of the recommended <ApplicationServices/ApplicationServices.h> as specified by the documentation.
Believe it or not, even in 10.8, you're still supposed to be importing AND linking ApplicationServices for this.

link against 'Current' version of Python.framework

I have a binary where I link to the Python.framework.
Via otool -L <binary>, it seems that it links against the full symlink-resolved path, i.e. /System/Library/Frameworks/Python.framework/Versions/2.7/Python and not /System/Library/Frameworks/Python.framework/Versions/Current/Python. From users which have only the Python 2.6 framework, I also got the report that it throws this error:
Dyld Error Message:
Library not loaded: /System/Library/Frameworks/Python.framework/Versions/2.7/Python
Referenced from: /Applications/MusicPlayer.app/Contents/MacOS/MusicPlayer
Reason: image not found
How can I tell Xcode that it should link to /System/Library/Frameworks/Python.framework/Versions/Current/Python?
Setting-up the Target's Link Binary with Libraries allows you a number of different versions. Use the unversioned libpython.dyld (top one):
You cannot link to the "Current" version, as it may be updated to point to a newer version that fundamentally breaks the library interface that you're linking against.

Resources