0

私のコンピュータに SWI-Prolog をインストールした後、そのサンプルの 1 つを試してみたところ、この特定の美しさを発見しました。

run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\swipl\bin\jpl.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at jpl.JPL.loadNativeLibrary(JPL.java:100)
    at jpl.fli.Prolog.<clinit>(Prolog.java:85)
    at jpl.Query.open(Query.java:286)
    at jpl.Util.textToTerm(Util.java:162)
    at jpl.Query.<init>(Query.java:198)
    at main.ProjetoPLP.main(ProjetoPLP.java:12)
Java Result: 1

確認したところ、前述のフォルダ内に jpl.dll ファイルがあるため、ここで何が起こっているのか正確にはわかりませんこのウェブサイトとインターネットで以前の質問をチェックしましたが、どちらも決定的な答えを提供しませんでした.

誰でもこれについてどうすればよいか考えていますか?

編集:

これが役立つ場合に備えて、実行しようとしているコードです。

package main;
import java.io.*;
import java.util.Hashtable;
import jpl.Query;
import org.apache.commons.io.*;

public class ProjetoPLP
{

    private static void loadJPLDll() {
    try {
        InputStream in = ProjetoPLP.class.getResourceAsStream("/test/resources/jpl.dll");
        File fileOut = new File("jpl.dll");
        OutputStream out = FileUtils.openOutputStream(fileOut);
        IOUtils.copy(in, out);
        in.close();
        out.close();
        System.load(fileOut.getAbsolutePath());// loading goes here
    } catch (Exception e) {
        e.printStackTrace();
    }
}
    public static void
    main(String args[] )
    {

                loadJPLDll();
        String t1 = "consult('family.pl')";
        Query q1 = new Query(t1);

        System.out.println( t1 + " " + (q1.hasSolution() ? "succeeded" : "failed") );

        //--------------------------------------------------

        String t2 = "child_of(joe, ralf)";
        Query q2 = new Query(t2);

        System.out.println( t2 + " is " + (q2.hasSolution() ? "provable" : "not provable") );

        //--------------------------------------------------

        String t3 = "descendent_of(steve, ralf)";
        Query q3 = new Query(t3);

        System.out.println( t3 + " is " +(q3.hasSolution() ? "provable" : "not provable") );

        //--------------------------------------------------

        String t4 = "descendent_of(X, ralf)";
        Query q4 = new Query(t4);

        System.out.println( "first solution of " + t4 + ": X = " + q4.oneSolution().get("X"));

        //--------------------------------------------------

        Hashtable[] ss4 = q4.allSolutions();

        System.out.println( "all solutions of " + t4);
        for ( int i=0 ; i<ss4.length ; i++ ) {
            System.out.println( "X = " + ss4[i].get("X"));
        }

        //--------------------------------------------------

        System.out.println( "each solution of " + t4);
        while ( q4.hasMoreSolutions() ){
            java.util.Hashtable s4 = q4.nextSolution();
            System.out.println( "X = " + s4.get("X"));
        }

        //--------------------------------------------------

        String t5 = "descendent_of(X,Y)";
        Query q5 = new Query(t5);

        System.out.println( "each solution of " + t5 );
        while ( q5.hasMoreSolutions() ){
            java.util.Hashtable s5 = q5.nextSolution();
            System.out.println( "X = " + s5.get("X") + ", Y = " + s5.get("Y"));
        }

    }

}
4

2 に答える 2

0

Windows の場合、環境パス設定を変更し、C:\Program Files (x86)\swipl\bin を追加します (その場所に swi-prolog がインストールされている場合)。または、次のように dll ファイルをロードすることもできます。

private static void loadDLL(String location) {
    try {
        File dll = new File(location);
        System.load(dll.getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    //load the dependent dll files
    loadDLL("libwinpthread-1.dll");
    loadDLL("libgcc_s_sjlj-1.dll");
    loadDLL("libgmp-10.dll");
    loadDLL("libswipl.dll");    
    loadDLL("json.dll");
    loadDLL("jpl.dll");

    //your code here
}

上記のコードを使用する場合は、添付された JPL.jar ファイルのネイティブ ライブラリの場所を追加する必要があります。Eclipse から java.library.path を設定する方法に従うことができます

于 2015-10-24T16:12:25.927 に答える