Error while running configure "Cannot locate libclang or headers"

Jorn Vernee jorn.vernee at oracle.com
Fri Nov 20 20:04:49 UTC 2020


Glad it worked!

Jorn

On 20/11/2020 20:26, Vipin Sharma wrote:
> Hi Jorn and Maurizio,
>
> Your suggestions are helpful, I could solve this problem. Explained 
> analysis in detail here.
>
> On Fri, Nov 20, 2020 at 8:18 PM Maurizio Cimadamore 
> <maurizio.cimadamore at oracle.com 
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>
>
>     On 20/11/2020 14:33, Jorn Vernee wrote:
>     > Hi,
>     >
>     > AFAIK if you're building from sources you need to use the cmake
>     > install target for it to produce a "package" that you can use I
>     think
>     > some headers might otherwise be missing.
>     >
>     >     cmake --build <build dir> --target install
>     >
>     > That will install at whatever CMAKE_INSTALL_PREFIX is set to
>     > (recommend setting this explicitly, instead of using the
>     default). You
>     > can point the jdk build at that afterwards package.
>     >
>     > That said, using a binary distribution might be easier, since it
>     > should already have the right directory structure.
>
>     I wonder if (i) the binary distro you have tried is compatible with
>     19.10 - I remember trying out several available on the LLVM
>     website few
>     months ago, and none of them worked out of the box on Ubuntu 20.04
>     (while many do on Ubuntu 18.04). Maybe 19.10 is in a similar boat
>
>
>
> Executed the gcc test with pre-built binaries, below are observations:
>
> command:
> gcc 
> -I/home/vipin/Softwares/clang+llvm-9.0.0-x86_64-pc-linux-gnu/include 
> -L/home/vipin/Softwares/clang+llvm-9.0.0-x86_64-pc-linux-gnu/lib 
> testClang.c -lclang
>
> Output:
> ... (some undefined reference errors similar to below example)
> /usr/bin/ld: 
> /home/vipin/Softwares/clang+llvm-9.0.0-x86_64-pc-linux-gnu/lib/libclang.so: 
> undefined reference to `Z3_solver_inc_ref'
> collect2: error: ld returned 1 exit status
> It fails probably because the clang binaries I am using are for Ubuntu 
> 19.04 and I am using version 19.10, seems you are right binary distro 
> I have used may not be compatible.
>
>
>     So it could be both the paths you tried fail, but for different
>     reasons
>     - as Jorn mentioned, the build you have might not be 100% ok - and
>     the
>     binary you downloaded might have dependencies that are not
>     satisfied on
>     your system.
>
>     The gcc test I suggested in the previous email should help in
>     narrowing
>     this down - if you see compilation/linker issues there, then we know
>     where to look.
>
>
> This is command executed to test this
> gcc -I/home/vipin/Softwares/llvm-project/build/include 
> -L/home/vipin/Softwares/llvm-project/build/lib testClang.c -lclang
>
> console output:
> testClang.c:1:10: fatal error: clang-c/Index.h: No such file or directory
>     1 | #include "clang-c/Index.h"
>       |          ^~~~~~~~~~~~~~~~~
> compilation terminated.
>
> I checked dir (clang build using source) 
> /home/vipin/Softwares/llvm-project/build/include/, below are its contents:
>
> vipin:/home/vipin/Softwares/llvm-project/build/include$ ls -ltr
> drwxr-xr-x 6 vipin vipin 4096 Nov 18 23:22 llvm
>
> And contents for dir 
> /home/vipin/Softwares/clang+llvm-9.0.0-x86_64-pc-linux-gnu/include 
> (pre-built clang binaries) are:
>
> vipin:/home/vipin/Softwares/clang+llvm-9.0.0-x86_64-pc-linux-gnu/include$ 
> ls -ltr
> llvm-c
> llvm
> c++
> polly
> clang-c
> clang
> lld
>
> in pre-built binaries, I can see we have include/clang-c/Index.h, 
> seems that is because I needed to execute one more step to install 
> clang, as Jorn suggested.
>
> I can confirm that this problem is resolved after using the below 
> command Jorn provided.
> cmake --build /home/vipin/Softwares/llvm-project/build --target install
>
> Just I could not use CMAKE_INSTALL_PREFIX properly so installation was 
> done in /usr/local/... directories.
> And because clang is available at /usr/local/bin, I don't need to 
> specify the clang install path in the configure command using 
> --with-libclang=
>
>
>     Maurizio
>
>     >
>     > HTH,
>     > Jorn
>     >
>     > On 20/11/2020 12:52, Maurizio Cimadamore wrote:
>     >>
>     >> On 19/11/2020 21:51, Vipin Sharma wrote:
>     >>> dir: /home/vipin/Downloads/clang+llvm-9.0.0-x86_64-pc-linux-gnu
>     >>> libexec
>     >>> include
>     >>> share
>     >>> lib
>     >>> bin
>     >>
>     >> This looks totally ok.
>     >>
>     >> Just one more test: can you run `clang` from there? Or do you get
>     >> errors pointing at missing dependencies?
>     >>
>     >> This is really odd. I have basically the same setup (except for
>     newer
>     >> Ubuntu), I have built clang sources from scratch, then pointed the
>     >> JDK build to the LLVM build folder and it all worked out.
>     >>
>     >> If all else fail, it would be nice to try and do what autoconf is
>     >> trying to do, which is to compile a small program against libclang
>     >> include/library and see if that works correctly. Something like:
>     >>
>     >> ```
>     >> $ cat testClang.c
>     >> #include "clang-c/Index.h"
>     >>
>     >> int main(void) {
>     >>    clang_getClangVersion();
>     >>    return 0;
>     >> }
>     >> ```
>     >>
>     >> Then try to compile it using gcc, and supply the "-I" (capital i)
>     >> option to point at the LLVM include folder, "-L" to point at
>     LLVM lib
>     >> folder, and then "-l clang" (lower case "L") to set linker
>     dependency
>     >> on libclang.
>     >>
>     >> E.g - in my system:
>     >>
>     >> ```
>     >> gcc -I/opt/clang/llvm-10/include -L/opt/clang/llvm-10/lib
>     testClang.c
>     >> -lclang
>     >> ```
>     >>
>     >> If you get compilation errors, or linker errors, then there's
>     >> something up with the environment. AFAIK, autoconf does something
>     >> like that to "check that libclang is really there".
>     >>
>     >> Maurizio
>     >>
>     >>
>     >>
>     >>
>
>
> Thanks,
> Vipin


More information about the panama-dev mailing list