How to include jxcore c++ library "jx.h" in qt applications?

87 Views Asked by At

This is the sample code I am trying execute in Qt Creator. I have included all the JX libraries in Qt. The JX c++ code works outside Qt well but I want to make it work inside Qt. Please review the code and suggest me a way to achieve this.

Currently I am getting errors such as "undefined reference to `v8::Locker::Locker(v8::Isolate*)'" and 1000 similar errors. I gues its because qt is not recognizing the JX libraries.

Thanks in advance.

#include "mainwindow.h"
#include <QApplication>
#include "jx.h"

#if defined(_MSC_VER)
// Sleep time for Windows is 1 ms while it's 1 ns for POSIX
// Beware using this for your app. This is just to give a
// basic idea on usage
#include <windows.h>
#else

#include <unistd.h>
#define Sleep(x) usleep(x)
#endif

void callback(JXValue *results, int argc) {
// do nothing
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    const char *contents =
        "process.requireGlobal = require;";

    JX_Initialize(argv[0], callback);
    JX_InitializeNewEngine();

    JX_DefineMainFile(contents);

    JX_StartEngine();

    JXValue ret_val;
    JX_Evaluate("process.requireGlobal('./dummy.js').data",
    "eval",&ret_val);

    while (JX_LoopOnce() != 0) usleep(1);

    JX_Free(&ret_val);
    JX_StopEngine();

    return a.exec();
}
1

There are 1 best solutions below

4
Andre On

Yes, the 'undefined reference to' is a linker error. This is due to the fact that the linker can't find the library (libraries) in the paths it already has, so you need to specified it (them) and you've to do it in the .pro file of your Qt project.

.pro file works similarly to makefile: here you have to specify "extra" paths where source and header files are located, as well as libraries. For your specific question, you need to add all the library requesting to make jxcore working, adding them to the keyword "LIBS": -L introduce path(s) at which libraries are stored, while -l introduce libraries themselves you want to use. I.e.

LIBS += -L/path/to/your/libraries \
        -lname_of_library_without_lib

You can find more detailed description at this link http://doc.qt.io/qt-4.8/qmake-project-files.html Go directly to last section if you're just interested in how add libraries

Hope it helps