UnsatisfiedLinkError 与 sbt 下的本机库 [英] UnsatisfiedLinkError with native library under sbt

查看:35
本文介绍了UnsatisfiedLinkError 与 sbt 下的本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sbt 0.13 并且在使用 sbt 下的 leveldbjni 本机库时遇到问题(即使在问题 #358 已解决).类似的问题已经被报告,sbt 0.13 应该提供一个解决方案,但似乎它没有.所以我在这里分享我的观察.

I'm using sbt 0.13 and have issues using the leveldbjni native library under sbt (even after issue #358 has been resolved). A similar issue has already been reported for which sbt 0.13 should provide a solution but it seems it doesn't. So I'm sharing my observations here.

我在使用以下示例应用程序时遇到 UnsatisfiedLinkError.

I'm getting an UnsatisfiedLinkError with the following example application.

  • build.sbt

  • build.sbt

name := "example"

version := "0.1"

scalaVersion := "2.10.2"

libraryDependencies += "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.7"

  • build.properties

  • build.properties

     sbt.version=0.13.0
    

  • 示例.scala

  • Example.scala

    import org.fusesource.leveldbjni.internal._
    
    object Example extends App {
      NativeDB.LIBRARY.load() // loading succeeds 
      new NativeOptions() // UnsatisfiedLinkError under sbt
    }
    

  • 我使用的是 Oracle JDK 1.7 和 OS X 10.8.5.在 sbt 下使用 run-main Example 运行示例给出

    I'm using Oracle JDK 1.7 and OS X 10.8.5. Running the example with run-main Example under sbt gives

    [error] (run-main) java.lang.UnsatisfiedLinkError: org.fusesource.leveldbjni.internal.NativeOptions.init()V
    

    而使用

    java -cp scala-library.jar:example_2.10-0.1.jar:leveldbjni-all-1.7.jar Example
    

    工作正常.当 Scala 在引导类路径上时,应用程序甚至可以成功运行:

    just works fine. The application even runs successfully when Scala is on the bootclasspath:

    java -Xbootclasspath/a:scala-library.jar -cp example_2.10-0.1.jar:leveldbjni-all-1.7.jar Example
    

    知道为什么只有在 sbt 下才有 UnsatisfiedLinkError 吗?

    Any ideas why there's an UnsatisfiedLinkError only under sbt?

    推荐答案

    知道为什么只有在 sbt 下才会出现 UnsatisfiedLinkError 吗?

    Any ideas why there's an UnsatisfiedLinkError only under sbt?

    正如@juereth 评论的:

    As @juereth commented:

    Sbt 正在使用魔法类加载器来尝试防止本机加载库的泄漏",并允许您多次重新导入库.Sbt 实际上会重命名 DLL/SO/jnilib 并将其加载到一个特殊的类加载器中.如果这只是一个插件功能,或者适用于所有应用的功能,我并不肯定.

    Sbt is using magic classloaders to try to prevent "leaks" of native loaded libraries, and allow you to re-import the library multiple times. Sbt will actually rename the DLL/SO/jnilib and load it in a special classloader. I'm not positive if this is only a plugin feature, or something for all apps.

    因此,这是 sbt 当前设计的某种预期行为.如果分叉有效,那么这就是你必须做的.

    So this is somewhat expected behavior with the current design of sbt. If forking works, then that's what you have to do.

    这篇关于UnsatisfiedLinkError 与 sbt 下的本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆