clang-rs icon indicating copy to clipboard operation
clang-rs copied to clipboard

clang-rs does not search LIBRARY_PATH and instead picks libraries in /usr/lib/xxx

Open molysgaard opened this issue 11 months ago • 0 comments

It seems that clang-rs does not search for libraries in the environment variable LIBRARY_PATH during execution of the build.rs script.

I am using GUIX (like NIX) and my library path is /gnu/store/qb41j953iam58gj3cwsz9jlnnfn25cwa-profile/lib. In that folder there is a libclang and libLLVM etc. But it seems that the build.rs script is instead linking with the libclang and libllvm that is present in /lib/x86_64-linux-gnu/. This leads to all sorts of linker errors, see snippet below:

  = note: ld: /lib/x86_64-linux-gnu/libedit.so.2: undefined reference to `__isoc23_wcstol@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `arc4random@GLIBC_2.36'
          ld: /lib/x86_64-linux-gnu/libbsd.so.0: undefined reference to `__isoc23_strtoimax@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `__isoc23_strtoull@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `__isoc23_sscanf@GLIBC_2.38'
          ld: /usr/lib/llvm-17/lib/libclang-17.0.6.so: undefined reference to `__isoc23_strtoul@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `std::condition_variable::wait(std::unique_lock<std::mutex>&)@GLIBCXX_3.4.30'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `fmodf@GLIBC_2.38'
          ld: /usr/lib/llvm-17/lib/libclang-17.0.6.so: undefined reference to `__isoc23_strtol@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `fmod@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `__isoc23_scanf@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libbsd.so.0: undefined reference to `__isoc23_strtoumax@GLIBC_2.38'
          ld: /lib/x86_64-linux-gnu/libLLVM-17.so.1: undefined reference to `__isoc23_strtoll@GLIBC_2.38'

Why fix this?

The LIBRARY_PATH variable is a convention established by gcc, and it makes sense to follow it. See here https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html#index-LIBRARY_005fPATH

How to fix this:

If LIBRARY_PATH is set, the build.rs script should search for libclang and similar in all the paths specified there, before it looks anywhere else. This is compatible with how gcc works.

molysgaard avatar Feb 29 '24 14:02 molysgaard