ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

libClangSharp not found ubuntu

Open GideonUng opened this issue 2 years ago • 7 comments

$ ClangSharpPInvokeGenerator --version ClangSharp P/Invoke Binding Generator version 13.0.0 Ubuntu clang version 13.0.0-2 Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load shared library 'libClangSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibClangSharp: cannot open shared object file: No such file or directory at ClangSharp.Interop.clangsharp.getVersion() at ClangSharp.Program.Run(InvocationContext context) in /_/sources/ClangSharpPInvokeGenerator/Program.cs:line 173 --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context) at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

GideonUng avatar Mar 03 '22 14:03 GideonUng

You'd likely need to use LD_DEBUG or ldd to determine which dependency is missing. My guess is that its not resolving libclang-cpp and that's causing the failure.

Since LLVM 14.0.0 released the other day, I'll be updating everything to v14.0.0 as well and will do some additional checks/steps to ensure libclang-cpp is available to resolve issues some users have hit.

tannergooding avatar Mar 25 '22 18:03 tannergooding

FWIW I'm also encountering this issue on OSX for version 13.0.0 too. I have confirmed all the dependencies exist - libclang.dylib and libclang-cpp.dylib are sitting next to each other, and from output with DYLD_PRINT_LIBRARIES it looks like libclang.dylib is loaded okay.

...
dyld[29341]: <6B1C6345-58B1-3633-ADD8-275001D24BC0> /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.3/libclrjit.dylib
dyld[29341]: <150A8A40-6E33-36CC-BC2A-A5E4BF7A5B7C> /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.3/libSystem.Native.dylib
dyld[29341]: <598B8E7E-C219-3BED-8CD0-9BCABE76932E> /Users/taylorgraham/node_modules/llvm-13.0.0.obj/lib/libclang.dylib
dyld[29341]: <833A181E-4354-3EBB-9B2C-597E0FD9407C> /usr/lib/libncurses.5.4.dylib
Unhandled exception: dyld[29341]: <3F532FC7-C442-31B7-B67B-97334BD3EB6E> /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.3/libSystem.IO.Compression.Native.dylib
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.DllNotFoundException: Unable to load shared library 'libClangSharp' or one of its dependencies. 

Does the version of libclang-cpp in libClangSharp matter here?

otool -L ~/.dotnet/tools/libClangSharp.dylib                                                                                                                                   
/Users/taylorgraham/.dotnet/tools/libClangSharp.dylib:
    @rpath/libClangSharp.13.0.0.dylib (compatibility version 13.0.0, current version 13.0.0)
    @rpath/libclang-cpp.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libclang.dylib (compatibility version 1.0.0, current version 13.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 904.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)

twgraham avatar Apr 04 '22 22:04 twgraham

This was an issue with not being able to resolve libclang-cpp

@rpath/libclang-cpp.dylib (compatibility version 0.0.0, current version 0.0.0)

v14.0.0, which was pushed last weekend, made sure to not depend on libclang-cpp so this issue should go away (you just need libclang which should get automatically pulled in via the other package references).

tannergooding avatar Apr 04 '22 22:04 tannergooding

Thanks @tannergooding! Will these changes be backported to 13 by any chance? I ask because the bindings I'm trying to generate are for a project using LLVM/Clang 13.0.0

twgraham avatar Apr 04 '22 23:04 twgraham

I'll see about doing it this weekend. Its going to require rebuilding LLVM/Clang v13.0.0 for all supported platforms and then rebuilding/packing libClangSharp, so its going to take some time to make happen

tannergooding avatar Apr 04 '22 23:04 tannergooding

issue persists for version 14.0.0-beta2 clang 14 probably needs to be installed? which isnt available on my distro yet.

GideonUng avatar Apr 05 '22 12:04 GideonUng

I was trying to roll clangsharp back to 13.0.0 and I ran into this issue. After reading through the comments here I got around this error by installing libclang-cpp13-dev on Ubuntu 22.04. Just thought I'd share in case it helps someone.

/home/shaun/.dotnet/tools/ClangSharpPInvokeGenerator --version

ClangSharp P/Invoke Binding Generator version 13.0.0
  clang version 13.0.0 (https://github.com/llvm/llvm-project/ 24c8eaec9467b2aaf70b0db33a4e4dd415139a50)
  clangsharp version 13.0.0

shaunrd0 avatar Jul 21 '22 12:07 shaunrd0

Closing as this is ultimately an issue with NuGet package restore.

v15.0.0 is providing a linux-x64 package as a "best effort" to help improve the experience. However, this is not guaranteed to work across all distros or distro versions due to how LLVM/Clang itself compiles under the hood.

tannergooding avatar Sep 18 '22 19:09 tannergooding