I am trying to compile a C source file, that needs to be linked against a dynamic library I installed through apt-get (libclang.so).

apt-get installed the clang shared libraries in /usr/lib/x86_64-linux-gnu/. Here are the relevant files :

$ ls -l /usr/lib/x86_64-linux-gnu/libclang*
lrwxrwxrwx 1 root root /usr/lib/x86_64-linux-gnu/libclang-3.4.so -> libclang-3.4.so.1
-rw-r--r-- 1 root root /usr/lib/x86_64-linux-gnu/libclang-3.4.so.1
lrwxrwxrwx 1 root root /usr/lib/x86_64-linux-gnu/libclang-3.5.so -> libclang-3.5.so.1
-rw-r--r-- 1 root root /usr/lib/x86_64-linux-gnu/libclang-3.5.so.1
lrwxrwxrwx 1 root root /usr/lib/x86_64-linux-gnu/libclang.so.1 -> libclang-3.5.so.1

The loader seems to know about libclang :

$ ldconfig -p | grep clang
        libclang.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libclang.so.1

In fact, my problem is reproducible no matter what the content of the source file I'm trying to compile is, as long as it contains valid code. So, I used this source file:

$ cat a.c 
int main(int argc, char** argv) {
  return 0;

Compiling against clang fails:

$ gcc a.c -L/usr/lib/x86_64-linux-gnu -lclang
/usr/bin/ld: cannot find -lclang
collect2: error: ld returned 1 exit status

But compiling against clang-3.5 (or clang-3.4) succeeds:

$ gcc a.c -L/usr/lib/x86_64-linux-gnu -lclang-3.5

I really need to be able to link using -lclang and not -lclang-3.5, because actually I cannot control how this compiler option is generated in my real-world problem. What can I do to make -lclang work ?

I'm using Ubuntu 14.04 LTS and GCC 4.8.2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.