What this error is sadly trying to tell you is that lib clang thinks its @rpath is at the root of your app bundle, but it's not.
I figured this out the hard way just the other day.
It's hard.
You have to do some crazy stuff with libclang.a using Build Phase settings.
In your target's Build Phases, you will need to add a few Run Script Phases.
One will be this:
echo "warning: OTOOL BEGIN1";
pwd;
otool -L ${SRCROOT}/Clangwrap/ClangAndLLVM/lib/libclang.dylib;
echo "Warning: OTOOL END1";
This just does a few things.
First it nicely sandwiches things with a log to see what happened.
The second is it really is just confirming the path to your lib once it's copied. (and yes, you should be copying it into your project to keep things sane.)
otool does this.
SRCROOT is the root of your project, then anything after that is your relative path within you project's folder in Finder to the lib you are going to use.
Again, this just confirms it is where you think it is.
Ok, next step. This is the real doozy.
echo "BEGIN install_name_tool";
install_name_tool -id @executable_path/../Frameworks/libclang.dylib ${SRCROOT}/Clangwrap/ClangAndLLVM/lib/libclang.dylib;
echo "END install_name_tool";
This runs the obscure command line tool install_name_tool and that is used to set the path where the lib thinks it is located within your app's bundle. Without doing this, the lib will think it is in some other path. You will be setting this path to what you intend it to be. In a Mac app, I used the Frameworks folder inside the bundle so I set it as such. The first argument to install_name_tool is the relative path in your app bundle where the lib is going to be. The second argument is where the lib is currently in your project so that install_name_tool can set its executable path.
This literally modifies a bit of the lib so it is loadable. libs must know their own load path.
Note the first step is only optional for your own sanity.
The second step is required, and both should occur before the Compile Sources Build Phase.
Click and drag to move them up.
Now the final step. Add a new Copy Files Phase and this will remain last in your build phases.
Set the destination to the same as the first arg of install_name_tool so you know your relative path is set and that's where you're going to put the lib.
I used Frameworks.
Now add the files to this Build Phase, for iPhone, add libclang.a (I don't think you can use libclang.dylib on iOS)
Note, you saw me use libclang.dylib and that's because I did this on a Mac app project. It should be the same process for just about anything.
this is not an easy or discoverable process, I pieced it together from several blogs and docs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…