MacOSX screensaver not loading due to Library not loaded: #rpath/libswiftAppKit.dylib - xcode

We have a working Mac OS X screensaver as a standalone Xcode project, but we needed to have it as a target in another Xcode project that also contains a related app.
I added a target for a screensaver, copied the code, added to that target, etc, etc. The code is the same one that works in the other screensaver, but on this one, it generates the following error:
2015-03-10 09:43:24.766 System Preferences[32495]: Error loading /Users/pupeno/Library/Screen Savers/Ninja.saver/Contents/MacOS/Ninja: dlopen(/Users/pupeno/Library/Screen Savers/Ninja.saver/Contents/MacOS/Ninja, 265): Library not loaded: #rpath/libswiftAppKit.dylib
Referenced from: /Users/pupeno/Library/Screen Savers/Ninja.saver/Contents/MacOS/Ninja
Reason: image not found
2015-03-10 09:43:24.766 System Preferences[32495]: ScreenSaverModules: can't get principalClass for /Users/pupeno/Library/Screen Savers/Ninja.saver
The library in question is definitely there:
$ ls -w1 Library/Screen\ Savers/Ninja.saver/Contents/Frameworks/
libswiftAppKit.dylib
libswiftCore.dylib
libswiftCoreGraphics.dylib
libswiftDarwin.dylib
libswiftDispatch.dylib
libswiftFoundation.dylib
libswiftObjectiveC.dylib
libswiftQuartzCore.dylib
libswiftSecurity.dylib
Any ideas what might be causing this?

The problem was that the Runpath Search Path, for some reason, in this new target, was blank. I fixed this problem by adding this:
#executable_path/../Frameworks #loader_path/../Frameworks
to it (which I took from the working screensaver configuration). This is how it looks like:

Like Pablo said, you need the following as your Runtime Search Path:
#executable_path/../Frameworks #loader_path/../Frameworks
This should be the default. Make sure it's there though. You also need to set Embedded Content Contains Swift Code to YES if you're using Swift. That took me awhile to figure out.
(Xcode should totally infer this. Oh well. I filed a radar for this awhile.)

Related

Runpath Search Paths can't find library even with #rpath/library.dylib

I've been banging my head against the wall on this for hours. I've been playing around with CMUSphinx's pocketsphinx library, running on OSX 10.10/XCode 7.2,and want to get my .app bundle to work on computers besides my own. Most importantly, there are three dynamic libraries that have to be embedded in the .app bundle(libpocketsphinx.3.dylib, libsphinxad.3.dylib, and libsphinxbase.3.dylib), and then loaded using Runpath Search Paths settings in XCode.
I've read just about everything I can find on how to get this to work. I should note that the .app bundle compiles/runs as intended on my own machine. I've made sure that the libraries are copied into the .app bundle's /Contents/Frameworks folder. The libraries are not using references, but are copied into my source folder (as per a forum post on this exact issue on CMUSphinx's page). I've tried just about every combination of using install_name_tool for #rpath/libraryname.dylib, as well as #loader_path and #executable_path in both the executable (so changing it in XCode to #whatever_path/../Frameworks), as well as the three library files. I also have tried #loader_path/Frameworks per another post here, but no luck.
Whats weird is the error I'm getting seems like it is loading libsphinxad.3.dylib, as both libsphinxad.3.dylib and libsphinxad.3.dylib rely on libsphinxbase.3.dylib, but I get this error in the crash report:
Dyld Error Message:
Library not loaded: /usr/local/lib/libsphinxbase.3.dylib
Referenced from: /Volumes/SunGate/VoiceCommander.app/Contents/Frameworks/libsphinxad.3.dylib
Reason: image not found
Note, the /Volumes/SunGate/ is just a drive on another machine I'm testing this on.
I would really appreciate help with this! I will do my best to provide any other information that might help solve this!
I found this lib by using the "find" command on my system. Not surprisingly it was here
sphinxbase/src/libsphinxbase/.libs/libsphinxbase.3.dylib
I linked it to /usr/local/lib/
ln -s sphinxbase/src/libsphinxbase/.libs/libsphinxbase.3.dylib /usr/local/lib/libsphinxbase.3.dylib
And all set to go!

dyld: Library not loaded: #rpath/libswiftContacts.dylib

dyld: Library not loaded: #rpath/libswift_stdlib_core.dylib
dyld: Library not loaded: #rpath/libswiftCore.dylib. Issue persist
I know that theses question have been answered several times, but "dyld: Library not loaded: #rpath/libswiftContacts.dylib" I have not been able to find a proper solution to this error when I am coding a Swift
application for XCode 7.2:
Here I use Contact & ContactUI Frameworks:: #rpath/libswiftContacts.dylib
dyld: Library not loaded: #rpath/libswiftContacts.dylib
Referenced from: /var/mobile/Containers/Bundle/Application/C0F2B5CB-628C-4643-9473-648D3099D8FB/HomeMadeFood_User.app/HomeMadeFood_User
Reason: image not found
I have tried all these actions:
Restarting Xcode, iPhone, computer
Cleaning & rebuilding
Revoking and creating new certificate/provision profile
Runpath Search Paths is '$(inherited) #executable_path/Frameworks'
Embedded Content Contains Swift Code is 'Yes'
Code Signing Identity is developer
deleting Xcode's Derived Data directory.
but I have always got the same error...
I tried like this: but i am getting an error like:
/Users/mac-jarc/Library/Developer/Xcode/DerivedData/HomeMadeFood_User-bmwdevsopruaqxfrbibhaspidobn/Build/Products/Debug- iphoneos/HomeMadeFood_User.app/Frameworks/Contacts.framework: bundle format unrecognized, invalid, or unsuitable
Command /usr/bin/codesign failed with exit code 1
I had this same error for a couple of weeks:
dyld: Library not loaded: #rpath/libswiftContacts.dylib
Basically I was able to run and test my app on device. Then about 2 weeks ago, I wasn't able to run the tests on device anymore. Tests were running fine on simulator. I can't think what changed. The error I saw was the one above. I searched Google for ages trying to find a solution, and tried many fixes unsuccessfully. The fix that finally worked was to delete the Derived Data. Once I did this, I was once again able to run the tests on my device.
Fix that worked for me:
Go to Xcode > Preferences > Locations > Derived Data (click on little arrow to open up the folder in finder)
e.g. /Users/[username]/Library/Developer/Xcode/DerivedData
Delete the entire DerivedData folder
Clean/Build
Test on device - finally works again
In our case, it was clear that there was a bug in the way Xcode was resolving dependencies to our target.
Let's me start by saying, the solution was:
import PassKit
Now, before you raise that eyebrow, here is why this worked:
We relied on a Swift framework that imports PassKit
We distributed the prebuilt binary to team members
The team observed the crash, just as OP mentioned it
Adding that import in the app target made Xcode embed the required swift libraries
Note: Just linking PassKit in the GUI did absolutely nothing.
Cracked it.
Check if the framework you're trying to build or one of it's dependency framework uses any of the Swift standard libraries. If yes, create a NEW key in the build settings
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
This error is caused due to invalid certification of Apple.
Go to your keychain access. Under "Keychains" select "System" and under "Category" select "Certificates". Check whether the "Apple Worldwide Developer Relations Certification Authority" is valid or not. If not download that certificate from Apple site. It'll solve the problem.
I know this is old question, but this is what helped me
Speaking shortly:
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES

How to use libclang in Xcode

I want to use the libclang library included with Xcode to do some simple source code parsing.
This is how I do it.
Figure out the libclang.dylib using echoxcode-select --print-path/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib
Copy the libclang.dylib file to my project folder.
Add it to a clean Xcode project (a Cocoa Application one).
Build and run the app
The built process runs fine but the app crash on start up with this error
dyld: Library not loaded: #rpath/libclang.dylib
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/ClassStructureAnalyzer-cthpbscauprydagysmerutpnhpua/Build/Products/Debug/ClassStructureAnalyzer.app/Contents/MacOS/ClassStructureAnalyzer
Reason: image not found
Adding the /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib to the runpath doesn't solve the problem.
I understand that this question may have been asked many times, but after googling for the whole day, I haven't figure out the answer yet :(
Thanks in advance!

linking glfw static library with Xcode 4

Okay I've been searching for hours to try and solve this but nothing has worked. This problem is very similar to other posts, but I none of their solutions work.
So I am writing an OpenGL program using glew and glfw and for some reason I am unable to get the program to compile. The error is on the include statement:
#include <GL/glfw.h>
and the error says 'GL.glfw.h' file not found.
I have followed all the instructions on the
GLFW-2.7.8 Release Notes
web page, which includes making glfw, and then importing the static library libglfw.a into Xcode. The library does show up under Build Phases -> Link Binary with Libraries, but apart from that Xcode doesn't seem to recognize it. For example, under the File Inspector it detects the file type as "Default - data".
The static library is configured for 64-bit architecture, which I am running.
I have tried changing the search paths under Build Settings.
I have the following frameworks included: Cocoa, OpenGL, and IOKit.
Please let me know if there is any more information you need to help me solve this problem and thank you for reading.
It turns out my glew was not importing correctly and so glfw did not work either.
These are the steps I took:
Changed the Base SDK from Latest OSX (10.8) to Current OSX.
After doing this, I "reduced" the error to an Apple Mach-O Linker (Id) error. Next:
Added -lGLEW to Other Linker Flags.
Added /opt/local/include/ to the header search paths
Added /opt/local/lib/ to the library search paths
Here is where I found my answer.

embedding multiple cross referencing frameworks in app bundle

so first off, I want to say that this question:
Bundle framework with application in XCode
and this question:
OSX: changing path of .framework
were both extremely helpful getting me up to this point, but I'm still not quite there.
So, like both the Original Posters for the two previous questions, I'm trying to embed a framework inside my app bundle. Or, rather, the issue is that I'm trying to embed MULTIPLE frameworks in my app bundle, some of which depend on eachother. I believe that even though my application can successfully find the frameworks (i've changed the install directory so the frameworks know where they are), the ones that reference each other are still looking for the frameworks to be installed in the normal ~/Library/Frameworks directory.
This is the output I'm getting when trying to run my app:
Dyld Error Message:
Library not loaded: #rpath/SDL.framework/Versions/A/SDL
Referenced from: /Users/Daly/Library/Developer/Xcode/DerivedData/Coin_Checkers_2-cibyiolfgsmcicdrcfxufftxzbsk/Build/Products/Debug/Coin Checkers 2.app/Contents/MacOS/../Frameworks/SDL_image.framework/SDL_image
Reason: image not found
Binary Images:
0x7fff5fc00000 - 0x7fff5fc3be0f dyld 132.1 (???) <29DECB19-0193-2575-D838-CF743F0400B2> /usr/lib/dyld
It seems to me that It's correctly loading SDL_image, but failing when SDL_image references SDL. Is there any similar trick I can use to direct the SDL_image framework to the correct location for my embedded SDL framework?
Thanks a bunch!
Oh, never mind. I hadn't seen this question until it showed up in the related section on the side:
Embedding frameworks in a Mac App Bundle
Apparently all I needed to do was set the runpath searchpath, and that solved all my problems. I had tried setting the Frameworks search path, but that didn't seem to help.
In fact, I redownloaded the frameworks to see if the install_name_tool steps were even necessary, and it seems they are not. they worked without it. Interesting.

Resources