I can answer part of your question about what is going wrong, I don’t know how to fix it.
Firstly, removing CXIndex index = clang_createIndex(0, 0); wouldn’t fix things if you didn’t have -Wl,--as-needed removal was only fixed because the linker noticed that you didn’t actually call libclang and therefore didn’t actually link your program without it CXIndex index = clang_createIndex(0, 0); .
The reason for the break is that any Mesa backend that you use (either ATI or NVIDIA) is also associated with clang. It seems that when your program is first loaded and dynamic links are allowed, the linker goes and loads the libclang links and other libclang LLVM files and runs the constructors for global objects, namely, how LLVM automatically registers it in passes. Thus, at this stage, all built-in LLVM passes are registered, then QT is launched and creates an OpenGL context, so Mesa loads the corresponding DRI server and, as it happens on your system, the backend uses clang / LLVM, and for some reason it seems that all of these constructors start up again, and LLVM notices that the “two” passes (actually the same pass that tries to register twice) have the same name and interrupt your program.
As I said, I don’t know why the constructors work twice, and I don’t know how to stop it. Try requesting the mesa-users mailing list; if you do not get an answer, try mesa-dev
Mesa mailing lists: http://mesa3d.org/lists.html
EDIT: you must make sure that your copy of Mesa is linked to the same version of LLVM that you are trying to use, if it does not fix the pass record, it will be the least of your problems.
Try ls /usr/lib64/llvm/libLLVM-?.?.so , if you have two things, you have two versions of libLLVM that are not a problem based on it, but if you are linking one version and Mesa links to another version that can explain things.