Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find libclang: "the libclang shared library #2360

Closed
cuifox opened this issue Nov 24, 2022 · 9 comments · Fixed by #2368
Closed

Unable to find libclang: "the libclang shared library #2360

cuifox opened this issue Nov 24, 2022 · 9 comments · Fixed by #2368

Comments

@cuifox
Copy link

cuifox commented Nov 24, 2022

apk info clang-dev
clang15-dev-15.0.5-r0 description:
A C language family front-end for LLVM (development files)

clang15-dev-15.0.5-r0 webpage:
https://llvm.org/

clang15-dev-15.0.5-r0 installed size:
21 MiB

cat /etc/alpine-release
3.15.1

--- stderr
thread 'main' panicked at 'Unable to find libclang: "the libclang shared library at /usr/lib/libclang.so.15.0.5 could not be opened: Dynamic loading not supported"', /root/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/bindgen-0.60.1/src/lib.rs:2172:31

@pvdrz
Copy link
Contributor

pvdrz commented Nov 24, 2022

well this says that dynamic loading is not supported, what happens if you use the static feature of bindgen?

EDIT: the runtime feature is enabled by default so you have to disable default features first. See https://docs.rs/crate/bindgen/0.60.1/features

@pvdrz
Copy link
Contributor

pvdrz commented Dec 6, 2022

A similar (but not exactly the same) issue happens here Rust-for-Linux/linux#934 and I suspect it is because the clang-sys version we use does not support clang 15.

We will update the clang-sys version and do a new release as soon as possible.

@Karrq
Copy link

Karrq commented Jun 17, 2023

Hello, I have the same issue but I'm using the latest version of bindgen (tried a couple of older versions too) and clang 12 with alpine 3.15.8

Unable to find libclang: "the `libclang` shared library at /usr/lib/libclang.so.12 could not be opened: Dynamic loading not supported

@pvdrz
Copy link
Contributor

pvdrz commented Jun 18, 2023

@Karrq have you tried this?

well this says that dynamic loading is not supported, what happens if you use the static feature of bindgen?

EDIT: the runtime feature is enabled by default so you have to disable default features first. See https://docs.rs/crate/bindgen/0.60.1/features

@Karrq
Copy link

Karrq commented Jun 18, 2023

@pvdrz I did, but then this is the error #2333

@Karrq
Copy link

Karrq commented Jun 19, 2023

I found the root cause: rust-lang/cargo#4423

I'm in a cross-compilation environment, thus RUSTFLAGS are ignored. The only sensible workaround (that I found for now) is using the host-config unstable feature

@quadroli
Copy link

Helloo 👋🏼
I'm getting the same same issue as well while trying to build wl-screenrec
I'm on Alpine Linux 3.19, and trying to use libclang16

Exact error message: Unable to find libclang: "the `libclang` shared library at /usr/lib/llvm16/lib/libclang.so.16.0.6 could not be opened: Dynamic loading not supported"

@quadroli
Copy link

How did you all work your way around this ?

@bnusunny
Copy link

bnusunny commented Sep 23, 2024

I had the same issue on Alpine Linux 3.20 and found one workaround. Here are the steps:

  1. Enable the static feature for bindgen in Cargo.toml
[build-dependencies]
bindgen = { version = "0.70", default-features=false, features = ["logging", "prettyplease", "static"] }
  1. Create a shell script in your project
#!/bin/bash
if [ "$1" = "--libs" ]; then
    /usr/bin/llvm-config "$@" "--link-static"
else
    /usr/bin/llvm-config "$@"
fi

You may need to adjust the /usr/bin/llvm-config path dependending on your system configuration.

And make it executable: chmod +x /path/to/the/script

  1. Set environment variable LLVM_CONFIG_PATH to the shell script created in the step 2.
export LLVM_CONFIG_PATH=/path/to/the/script

The last 2 steps is to workaround a bug in clang-sys here. It misses --link-static option when using llvm-config to list the static libs (.a). Without that option, llvm-config gives the dynamic libs (.so).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants