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.
Related
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"
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.
I have a issue with dependencies in my dylibs.
I currently get the follwing error message:
dyld: Library not loaded: /opt/local/lib/libgvc.6.dylib
Referenced from: /Users/klauskneupner/Library/Developer/Xcode/DerivedData/Visual_Thinking-bvgfcqjwnobabodenabpggrwnoet/Build/Products/Debug/Visual Thinking.app/Contents/Frameworks/libgvplugin_dot_layout.6.dylib
Reason: image not found
The funny part is that I have that library (libgvc.6) in the list of dependencies.
But in this case, the libgvc.6 is in a project directory and not in /opt/local/lib.
What do I need to do? Many thanks in advance!
At build time the static linker on OS X, ld, writes the shared library identifier of each library that your application links against in to the application binary. At run time the dynamic linker, dyld, attempts to load each shared library from the paths specified in the application binary. You can see this information using otool -L YourApp.app/Contents/MacOS/YourApp.
The reference to /opt/local/lib/libgvc.6.dylib in your crash output indicates that is the shared library identifier of libgvc.6.dylib in your project. To include the library in your .app bundle in a way that your application will use it rather than looking in /opt/local/lib you need to:
Change the shared library identifier of libgvc.6.dylib so that dyld will look for the binary within your application bundle. This is typically done by running install_name_tool -id #rpath/libgvc.6.dylib libgvc.6.dylib. The #rpath placeholder tells dyld to try substituting each of the entries in the runpath search path of the binary that is loading the library. By default your app bundle's Frameworks directory is on this search path.
Update any existing prebuilt libraries that link to libgvc.6.dylib to refer to it via the new name (the change made in step 1 only takes effect when a new binary is built against the library, so it may not be necessary if it is only prebuilt libraries that link against it). You can use install_name_tool -change /opt/local/lib/libgvc.6.dylib #rpath/libgvc.6.dylib path/to/other.dylib to update these other libraries. Your crash output shows that libgvplugin_dot_layout.6.dylib is one such library that would need updated. It may not be the only one.
Ensure that your modified libraries are being copied in to the Frameworks subdirectory in your application bundle. This is typically done using a Copy Files build phase in your Xcode project.
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.
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.