'How to include libclang as a dependency using meson?
I am trying to use libclang for some source parsing on linux. I have libclang-dev installed and it appears under the list of packages for apt on my system.
However when i try to add it as a dependency through any of:
dependency('clang')
dependency('libclang')
dependency('libclang-dev')
dependency('libclang-cpp-dev')
In all cases I get
Run-time dependency clang found: NO (tried pkgconfig and cmake)
Despite it no being able to find it in my system I thought I could just compile it from source. To that effect I tried this:
opt_var = cmake.subproject_options()
opt_var.append_link_args('-fPIC')
sub_proj = cmake.subproject('clang', options : opt_var)
clang = sub_proj.dependency('clang')
Which gives :
../subprojects/clang/meson.build:0:0: ERROR: Can't link non-PIC static library 'clangBasic' into shared library 'clang_cpp'. Use the 'pic' option to static_library to build with PIC.
I tested compilation of clang outside of meson (i.e. i made a build directory and did cmake .. && make) and it works so this is a problem with how meson is calling cmake, not with the library.
Any ideas?
Solution 1:[1]
I found a temporary solution but I hate it because it's too system specific, you can add the following:
cpp = meson.get_compiler('cpp')
includes = include_directories(['/usr/lib/llvm-13/include/'])
libclang_lib = cpp.find_library('clang', dirs:'/usr/lib/llvm-13/lib', header_include_directories: includes)
libclang = declare_dependency(dependencies:libclang_lib, include_directories:includes)
To your meson script. Then use libclang as a dependency.
I am still interested in an answer that is more general/less OS specific.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Makogan |
