简体   繁体   English

Alloy API导致java.lang.UnsatisfiedLinkError

[英]Alloy API resulting in java.lang.UnsatisfiedLinkError

I'm currently using the Alloy Analyzer API to build a program, and getting some peculiar behavior. 我目前正在使用Alloy Analyzer API来构建程序,并得到一些特殊的行为。 Specifically, if I open a file and parse it (using CompUtil.parseEverything), then make a new Command and call TranslateAlloyToKodkod.execute_command on the parsed file and newly created command using MiniSat with UNSAT core, it runs fine. 具体来说,如果我打开一个文件并对其进行解析(使用CompUtil.parseEverything),然后执行一个新命令,然后对解析后的文件调用调用TranslateAlloyToKodkod.execute_command,并使用具有UNSAT核心的MiniSat新建命令。 However, later in execution, my program parses a second input file (also using CompUtil.parseEverything), gets another world, makes a new command, and then I try to call TranslateAlloyToKodkod.execute_command again, it throws the following error: 但是,在以后的执行中,我的程序解析第二个输入文件(也使用CompUtil.parseEverything),获取另一个世界,创建新命令,然后尝试再次调用TranslateAlloyToKodkod.execute_command,它引发以下错误:

ERROR: class edu.mit.csail.sdg.alloy4.ErrorFatal: The required JNI library cannot be found: java.lang.UnsatisfiedLinkError: no minisatproverx5 in java.library.path edu.mit.csail.sdg.alloy4compiler.translator.TranslateAlloyToKodkod.execute_command(TranslateAlloyToKodkod.java:390)

Does anyone have any idea why this is thrown the second time, but not the first? 有谁知道为什么第二次而不是第一次抛出?

To summarize, I have something similar to the following: 总而言之,我有类似以下内容:

Module someWorld = CompUtil.parseEverything_fromFile(rep, null, "someFile.als");
//For the following, "sig" is a sig in someWorld.getAllReachableSigs();
Command command = sig.not();
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.MiniSatProverJNI;
A4Solution ans = 
    TranslateAlloyToKodkod.execute_command(rep, someWorld, command, options);
//No thrown error
Module someOtherWorld = CompUtil.parseEverything_fromFile(rep, null, "someOtherFile.als");
//For the following, "sig" is a sig in someOtherWorld.getAllReachableSigs();
Command commandTwo = sig.not();
A4Solution ansTwo = 
    TranslateAlloyToKodkod.execute_command(rep, someOtherWorld, commandTwo, options);
//Thrown error above. Why?

I tried to reproduce this behavior, but I couldn't. 我试图重现这种行为,但是我做不到。 If I don't add MiniSat binaries to the LD_LIBRARY_PATH environment variable, I get the exception you mentioned the very first time I invoke execute_command . 如果不将MiniSat二进制文件添加到LD_LIBRARY_PATH环境变量中,则会得到您第一次调用execute_command时提到的异常。 After configuring LD_LIBRARY_PATH, the exception doesn't happen. 配置LD_LIBRARY_PATH之后,不会发生异常。

To configure LD_LIBRARY_PATH: 要配置LD_LIBRARY_PATH:

(1) if using Eclipse, you can right-click on one of your source folders, choose Build Path -> Configure Build Path, then on the "Source" tab make sure that "Native library location" points to a folder in which MiniSat binaries reside. (1)如果使用Eclipse,则可以右键单击一个源文件夹,选择“构建路径”->“配置构建路径”,然后在“源”选项卡上确保“本机库位置”指向MiniSat所在的文件夹二进制文件驻留。

(2) if running from the shell, just add the path to a folder with MiniSat binaries to LD_LIBRARY_PATH, eg, something like export LD_LIBARRY_PATH=alloy/extra/x86-linux:$LD_LIBRARY_PATH . (2)如果从外壳运行,只需将MiniSat二进制文件的路径添加到LD_LIBRARY_PATH,例如,诸如export LD_LIBARRY_PATH=alloy/extra/x86-linux:$LD_LIBRARY_PATH的路径。

Here is the exact code that I was running, and everything worked 这是我运行的确切代码,一切正常

public static void main(String[] args) throws Exception {
    A4Reporter rep = new A4Reporter();

    A4Options options = new A4Options();
    options.solver = A4Options.SatSolver.MiniSatProverJNI;

    Module someWorld = CompUtil.parseEverything_fromFile(rep, null, "someFile.als");
    Command command = someWorld.getAllCommands().get(0);
    A4Solution ans = TranslateAlloyToKodkod.execute_command(rep, someWorld.getAllReachableSigs(), command, options);
    System.out.println(ans);

    Module someOtherWorld = CompUtil.parseEverything_fromFile(rep, null, "someOtherFile.als");
    Command commandTwo = someOtherWorld.getAllCommands().get(0);
    A4Solution ansTwo = TranslateAlloyToKodkod.execute_command(rep, someOtherWorld.getAllReachableSigs(), commandTwo, options);
    System.out.println(ansTwo);
}

with "someFile.als" being 与“ someFile.als”是

sig A {}
run { some A } for 4

and "someOtherFile.als" 和“ someOtherFile.als”

sig A {}
run { no A } for 4

I use alloy4.2.jar as a library in my eclipse plugin project. 我在我的eclipse插件项目中将Alloy4.2.jar用作库。

A4Reporter rep = new A4Reporter();
Module world = CompUtil.parseEverything_fromFile(rep, null, "civi.als");
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.SAT4J;
options.skolemDepth = 1;

When I use SAT4J, the default solver, the problem mentioned here will not show up. 当我使用默认求解器SAT4J时,这里提到的问题将不会出现。 But another exception comes out. 但是另一个例外出现了。 The reason is that my civi.als file need Integer model, which located in alloy4.2.jar under the folder /models/util/. 原因是我的civi.als文件需要Integer模型,该模型位于Alloy4.2.jar中的/ models / util /文件夹下。 But when I run the application, it tries to find the file util/Integer.als directly. 但是,当我运行该应用程序时,它将尝试直接找到文件util / Integer.als。 That causes the exception. 这导致异常。 Is it possible to fix that problem? 有可能解决该问题吗?

Besides, I also tried to put the alloy4.2.jar in eclipse plugin project and run my application as an eclipse application (running my application as a plugin). 此外,我还尝试将Alloy4.2.jar放在eclipse插件项目中,并将我的应用程序作为eclipse应用程序运行(将我的应用程序作为插件运行)。 With the default solver, the application has no problem at all. 使用默认的求解器,应用程序完全没有问题。 But when I switch to MiniSatProverJNI, the problem mentioned here comes out (I have set the alloy4.2.jar as classpath). 但是,当我切换到MiniSatProverJNI时,这里提到的问题就出来了(我已经将Alloy4.2.jar设置为类路径)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM