How to use libclang in Xcode - 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!

Related

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

Why do I have to embed my libraries inside my applications binary for them to work?

So I followed this tutorial:
http://locomoviles.com/ios-tutorials/create-ios-cocoa-touch-framework-using-xcode/
Everything went fine except when I went to run the program I got the following error:
> dyld: Library not loaded:
> #rpath/SwiftFramework.framework/SwiftFramework Referenced from:
> /Users/bluke/Library/Developer/CoreSimulator/Devices/40677D10-F22B-4AE4-B767-06439AB7887A/data/Containers/Bundle/Application/8C6A5F76-C666-4B69-9353-A0ABD7DA085B/UseFramework.app/UseFramework
> Reason: image not found
I was able to solve this problem by adding the framework as an embedded binary, but I don't understand why this was needed to solve the problem.
I thought that the framework would be included in my application bundle as a dynamically linked library (i.e. not embedded in my application's binary directly) and then linked at run time. Is this assumption incorrect?
Just in case my question was unclear, I've added the following pictures.
This is what was producing the error:
If I add the framework to the embedded binaries it works:
I thought that the framework would be included in my application
bundle as a dynamically linked library (i.e. not embedded in my
application's binary directly) and then linked at run time. Is this
assumption incorrect?
Yes, it's incorrect. iOS apps link 3rd party frameworks statically, not dynamically. This prevents apps from downloading and dynamically linking code that hasn't been vetted by the app store review process.
This allows apps coded in Swift to run on devices running a version of iOS pre-dating Swift (earlier than iOS8).
Non-Apple frameworks can be embedded on iOS8 and above only.
It is also nice to add a prefix the the name identifying the developer organization so as to avoid comflicts and confusion. "SwiftFramework" looks so much like an Apple framework.

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

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

How do I add Gosu framework for XCode4 project?

I have little to no knowledge about linking and referencing files/resources when it comes to compiled languages (I'm a Ruby programmer).
I'm trying my best using general tutorials on "how to add a framework to XCode 4 project", but I'm having a rough time trying to understand how am I supposed to do this, as everything I do fails in the end.
I've simply created a new cocoa application, went to build phases / Link Binary With Libraries and added Gosu.framework there. I didn't do anything else.
Now when I try to run the application, I get this error:
dyld: Library not loaded: #executable_path/../Frameworks/Gosu.framework/Versions/A/Gosu
Referenced from: /Users/ellmo/Library/Developer/Xcode/DerivedData/gosuTest-hkmqdspnwjepredgslldpnmuhlvx/Build/Products/Debug/gosuTest.app/Contents/MacOS/gosuTest
Reason: image not found
What should I do?

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