Static linking libclang in C code
I am trying to write a simple syntax check for C code using the interface available in libclang. Due to deployment issues, I should be able to statically link all libraries in libclang, rather than passing in the .so file that all libraries have.
I am building clang / llvm from source and in llvm / Release + Asserts / lib I have a bunch of .a files I think I can use but it never works (linker links from thousands of errors about missing symbols). However, when I compile it using libclang.so, I am also present in that directory like this:
clang main.c -o bin/dlc -I../llvm/tools/clang/include -L../llvm/Release+Asserts/lib/ -lclang
Everything seems to work well.
What is the minimum set of .a files I need to include in order to make this work? I have tried to include absolutely all .a files in the build output directory, and they were provided by clang / gcc on various orders without any success. I only need the functions mentioned in libclang Index.h, but there doesn't seem to be any resources or documentation on what the various libclang * .a files are for. It would be very helpful to know what libclang.so files are being loaded.
source to share
The job is supposed to get done since the whole project has all static libraries (I counted 116 in the Release / lib directory).
clang main.c -o bin / dlc -I ../ llvm / tools / clang / include ../ llvm / Release / lib / *. a
[edit: clang main.c -o bin / dlc -I ../ llvm / tools / clang / include ../ llvm / Release / lib / libclang.a ../ llvm / Release / lib / *. and]
Note that the output binary is not static, so you don't need any -static flag for gcc or ld if you use this syntax.
If that doesn't work, you may need to list the libraries in order: if a library requires a function that is available in another library, you may need to list it first on the command line. See Comments on link order at: http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Link-Options.html#Link-Options
source to share