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

Static linking doesn't work #174

Closed
theoparis opened this issue May 16, 2024 · 6 comments
Closed

Static linking doesn't work #174

theoparis opened this issue May 16, 2024 · 6 comments

Comments

@theoparis
Copy link

theoparis commented May 16, 2024

Caused by:
  process didn't exit successfully: `/home/theo/dev/raknet/target/debug/build/clang-sys-6b084d6bff3d9148/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at /home/theo/.cargo/git/checkouts/clang-sys-67ca2c90881f88fe/ab99460/build/static.rs:90:9:
  could not find any static libraries
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After I fixed #168 in my fork, I realized clang-sys tries to find libclang.a which doesn't exist. Instead it should be using all of the clang libraries (libclang*.a, not a singular libclang.a)

@theoparis
Copy link
Author

theoparis commented May 19, 2024

Is this library still being maintained? I am still encountering my two issues and this breaks the entire rust ecosystem on my end - meaning everything that relies on bindgen is unusable. Additionally it seems like there are issues from 2021 with no response....

Maybe this project could get moved to the rust-lang organization in the future?

@KyleMayes
Copy link
Owner

KyleMayes commented May 27, 2024

I'm pretty sure static linking only works when libclang.a is available, but this isn't included in most builds.
(e.g., sudo apt install libclang-dev on Ubuntu won't include libclang.a).

I'm looking into building libclang.a from source and seeing if static linking still works with that approach.

If that is the case, I think the documentation and error messages can be improved to make this more clear.

@theoparis
Copy link
Author

Yeah, I did try using clang built from source but maybe I missed a cmake option to build everything as a single libclang.a file, not sure. Currently I have a libclang.so and a bunch of libclangXYZ.a libraries.

@KyleMayes
Copy link
Owner

This worked for me (in a freshly cloned llvm-project repo):

cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS=clang -DLIBCLANG_BUILD_STATIC=ON
ninja -C build

That (eventually) produced build/lib/libclang.a.

Then, after setting the LLVM_CONFIG_PATH environment variable to point to the newly built llvm-config, I was able to run cargo test --features static in clang-sys with no issues.

(Note: It was taking ages to link the zillions of LLVM/Clang static libraries until I switched to nightly Rust which uses lld instead of ld for linking)

@KyleMayes
Copy link
Owner

I've updated the error message for when static linking fails to find libclang.a and added a section to the README about how most users will probably need to build libclang.a themselves since it usually isn't included in most distributions of LLVM / Clang.

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

No branches or pull requests

2 participants