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

Does not build on Linux #336

Closed
zeule opened this issue Apr 14, 2022 · 10 comments
Closed

Does not build on Linux #336

zeule opened this issue Apr 14, 2022 · 10 comments

Comments

@zeule
Copy link
Contributor

zeule commented Apr 14, 2022

On Gentoo the build fails with:

/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lclangAST
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lclangFrontend

Both libraries do not exist in my system.

@zeule
Copy link
Contributor Author

zeule commented Apr 14, 2022

$ grep add_library /usr/lib/llvm/*/lib64/cmake/clang/ClangTargets.cmake
/usr/lib/llvm/13/lib64/cmake/clang/ClangTargets.cmake:add_library(clang-cpp SHARED IMPORTED)
/usr/lib/llvm/13/lib64/cmake/clang/ClangTargets.cmake:add_library(libclang SHARED IMPORTED)
/usr/lib/llvm/14/lib64/cmake/clang/ClangTargets.cmake:add_library(clang-cpp SHARED IMPORTED)
/usr/lib/llvm/14/lib64/cmake/clang/ClangTargets.cmake:add_library(libclang SHARED IMPORTED)

@zeule
Copy link
Contributor Author

zeule commented Apr 14, 2022

Please revert fe454e0

@zeule zeule changed the title Does not build with clang 14 Does not build on Linux Apr 15, 2022
@zeule
Copy link
Contributor Author

zeule commented Apr 15, 2022

See #244.

@tannergooding
Copy link
Member

You'll need to build https://github.com/llvm/llvm-project/tree/llvmorg-14.0.0 locally to get access to the required lib packages given they are not distributed by default in all distros or Operating Systems.

While linking against clang-cpp makes it easier for Gentoo to build "by default", it makes the experience worse on other platforms and causes the libClangSharp to no longer work by default on most platforms due to clang-cpp not being resolvable.

@zeule
Copy link
Contributor Author

zeule commented Apr 15, 2022

You'll need to build https://github.com/llvm/llvm-project/tree/llvmorg-14.0.0 locally

No, I don't. There was a test in #244, which prefers clang-cpp library, so linking was conditional thus making no problems for other platforms or clang builds with other options enabled. If you want to prefer the other library set, let's invert the test: if (TARGET clang-ast AND TARGET clang-frontend) (please check target names in your ClangTargets.cmake.

@tannergooding
Copy link
Member

Dealing with n+ Linux distributions and the various quirks and oddities that each has in how they package and distribute binaries is out of scope of the project.

Referencing clang-cpp was causing many more problems than it was solving and was breaking the user experience for other "officially supported" platforms because the file wasn't resolvable by default.

The simpler thing is to simply require devs to compile libclang locally before compiling libClangSharp so that all platforms have a consistent experience and expectations. It reduces the overall risk, increases portability, and ensures that we're only relying on dynamic libraries that are available on every platform.

@zeule
Copy link
Contributor Author

zeule commented Apr 20, 2022

I'm afraid you are mistaken about the packaging process for Linux distributions: we strongly prefer dynamic libraries over static ones. I doubt you can find any distro without the clang-cpp .so library. Neither can I understand the mentioned problems. Referencing the clang-cpp library was under conditional test (if (TARGET clang-cpp)), thus the library has to be available to the linker when the test passes. Could you elaborate on the problems, please?

…ensures that we're only relying on dynamic libraries that are available on every platform

clangAST and clangFrontend are static libs, clang-cpp is the dynamic one.

@tannergooding
Copy link
Member

Referencing the clang-cpp library was under conditional test (if (TARGET clang-cpp)), thus the library has to be available to the linker when the test passes

Available when the linker runs and not available at runtime for people wanting to just install a .NET tool (ClangSharpPInvokeGenerator) and then run it.

clangAST and clangFrontend are static libs, clang-cpp is the dynamic one.

Yes. The point is that libClang is itself a "standalone" DLL that exposes several imports and statically links in clangAST, clangFrontend, and friends.
libClangSharp is meant to be an extension of libClang and function in the same manner that it is "standalone" and doesn't require an existing Clang or LLVM install.

It should be sufficient to merely distribute libClang and libClangSharp SxS with the relevant tooling and for it to work.

Having libClangSharp dynamically link against clang-cpp breaks this expectation and this experience.

@zeule
Copy link
Contributor Author

zeule commented Apr 20, 2022

Ah, so that's what you want! Statically linked binaries! Thank you, now I understand. Then I figure we can replace the test for clang-cpp target with the opposite one for clangAST and clangFrontend and prefer them when they are available. I can submit a PR with the required changes to the CMake build script and I would appreciate if you share with me with the ClangTargets.cmake file from the Windows build of clang with the clangAST & clangFrontend static libraries, please.

@zeule
Copy link
Contributor Author

zeule commented Apr 20, 2022

if you share with me with theClangTargets.cmake file from the Windows build of clang with the clangAST & clangFrontend static libraries

Pardon, found one online.

zeule added a commit to zeule/ClangSharp that referenced this issue Apr 20, 2022
Linux distributions prefer dynamic libraries but we'd like to link to
Clang statically. Therefore we return the test for clang targets but
extend it to prefer static Clang libraries and fall back to the
clang-cpp library when the static ones are unavailable.

Fixes dotnet#336.
zeule added a commit to zeule/ClangSharp that referenced this issue Apr 21, 2022
Add build option to control which type of clang libraries (shared or
static) link to.

Fixes dotnet#336.
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.

2 participants