Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Add Prolog in a Qt application

    General and Desktop
    2
    3
    1448
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Amott last edited by

      Hello everyone,

      I need to add an AI in my application and to do that, I decided to work with Prolog.
      I downloaded SWI-Prolog here (32bit version, as I build my project with Qt 5.8 MinGW 32bit), and I installed it.

      Then I added the libswipl.lib to my project (right clic / Add library on QtCreator), here is what my .pro looks like :

      #-------------------------------------------------
      #
      # Project created by QtCreator 2017-03-19T17:55:04
      #
      #-------------------------------------------------
      
      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = TestProlog
      TEMPLATE = app
      
      SOURCES += main.cpp
      
      win32: LIBS += -L$$PWD/'../../../../../Program Files (x86)/swipl/lib/' -llibswipl
      
      INCLUDEPATH += $$PWD/'../../../../../Program Files (x86)/swipl/include'
      DEPENDPATH += $$PWD/'../../../../../Program Files (x86)/swipl/include'
      
      win32:!win32-g++: PRE_TARGETDEPS += $$PWD/'../../../../../Program Files (x86)/swipl/lib/libswipl.lib'
      
      
      

      After that, I wanted to test if everything is ok, so I took an example on the internet, here is my main.cpp :

      #include <QApplication>
      #include <QInputDialog>
      #include <QMessageBox>
      
      #include <SWI-Prolog.h>
      #include <SWI-cpp.h>
      #include <SWI-Stream.h>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          PlEngine e(argc, argv);
          QString pal = QInputDialog::getText(0, "Palindrome check", "enter text");
          PlTerm ATOM = PlAtom(qPrintable(pal.toUtf8())), LIST;
          PlCall("atom_codes", PlTermv(ATOM, LIST));
          if (PlCall("reverse", PlTermv(LIST, LIST)))
              QMessageBox::information(0, "outcome", "is a palindrome");
          else
              QMessageBox::information(0, "outcome", "is NOT a palindrome");
      
          return 0;
      }
      
      

      It successfully build, but when I run the application, it crashes immediately. I tried to debug it by setting a break point on the first line and and error ocurred "During startup program exited with code 0xc0000135".
      If I comment Prolog related lines, the application runs normally.

      What am I doing wrong ? Did I missed something ?

      Thanks in advance for your help, have a good day !

      E 1 Reply Last reply Reply Quote 0
      • E
        Eeli K @Amott last edited by

        @Amott You are probably missing some .dll library. I don't know which one. Try http://www.dependencywalker.com/.

        1 Reply Last reply Reply Quote 2
        • A
          Amott last edited by

          Thanks Eeli K, you were right !
          I needed to put 2 DLLs from Prolog into my directory (libswipl.dll and libgmp-10.dll) !
          Thanks a lot !

          1 Reply Last reply Reply Quote 0
          • First post
            Last post