Ivan Akulov Ivan Akulov - 2 years ago 210
C++ Question

Undefined reference to QJson::Parser::Parser

I've successfully(?) installed the QJson library following the instructions in the archive. But the compiler gives me this error:

Undefined reference to QJSon::Parser::Parser().

I've found where library files have been installed: it's
directory. But there are only
files in it.

The minimal code:


#include <QtGui/QApplication>
#include <qjson/parser.h>

int main(int argc, char *argv[])
QApplication a(argc, argv);
QJson::Parser parser;
return a.exec();

I use linux.

Where are
files? What did I do wrong? Why isn't the library complete?

Answer Source

At first you have to find a library file rather than a *.cpp file. Maybe it has a name like "libqjson.a" or "libqjson.so" and compile this library with your code or pass this keys to

g++ -L(lib path) -lqjson

As it turned out (see comments below), your library path is /usr/local/lib, so this line becomes:

g++ -L/usr/local/lib -lqjson

Using Qt (qmake), just add this line to your .pro file in order to pass these two flags to g++:

LIBS += -L/usr/local/lib -lqjson
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download