serenadeai / java-tree-sitter

Java bindings for tree-sitter
MIT License
126 stars 35 forks source link

`java.lang.UnsatisfiedLinkError` when setting language #33

Open PawanKartikS opened 8 months ago

PawanKartikS commented 8 months ago

I was able to successfully build the dynamic library using: ./build.py -o libjava-tree-sitter ../tree-sitter-c-sharp-master.

I'm also able to load the library successfully. However, when I try to set the language to C# via parser.setLanguage(Languages.cSharp()), I get a linkage error:

Exception in thread "sbt-bg-threads-1" java.lang.UnsatisfiedLinkError: 'long ai.serenade.treesitter.Languages.cSharp()'
    at ai.serenade.treesitter.Languages.cSharp(Native Method)
    at astute.Main$package$.main(Main.scala:11)
    at astute.main.main(Main.scala:7)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at sbt.Run.invokeMain(Run.scala:144)
    at sbt.Run.execute$1(Run.scala:94)
    at sbt.Run.$anonfun$runWithLoader$5(Run.scala:121)
    at sbt.Run$.executeSuccess(Run.scala:187)
    at sbt.Run.runWithLoader(Run.scala:121)
    at sbt.Defaults$.$anonfun$bgRunTask$6(Defaults.scala:1988)
    at sbt.Defaults$.$anonfun$termWrapper$2(Defaults.scala:1927)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at scala.util.Try$.apply(Try.scala:213)
    at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:367)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1583)

I was wondering if I could receive some help. And for note, I'm performing the above steps on an M1 Mac and yes, I did take a look at the in-progress PR. It was that PR that helped me successfully build the dynamic library.

sogaiu commented 8 months ago

Sorry that this response is not an answer to your question.

I think it's worth considering the content starting here that mention a few other efforts toward using tree-sitter from Java (including a fork of this repository that might have the issue addressed).

PawanKartikS commented 8 months ago

I've tried what you've suggested and now I seem to be getting SIGSEGV when loading in the library:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000001046f630c, pid=45986, tid=57199
#
# JRE version: Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (21.0.2+13) (build 21.0.2+13-LTS-jvmci-23.1-b30)
# Java VM: Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (21.0.2+13-LTS-jvmci-23.1-b30, mixed mode, sharing, tiered, jvmci, jvmci compiler, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64)
# Problematic frame:
# V  [libjvm.dylib+0x54e30c]  jni_GetFieldID+0x148
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

Edit: I've opened an issue here: https://github.com/seart-group/java-tree-sitter/issues/138.