Important: Please read the Qt Code of Conduct -

Add Prolog in a Qt application

  • 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");
            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 !

  • @Amott You are probably missing some .dll library. I don't know which one. Try

  • 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 !

Log in to reply