I know it's a stupid question, but still.
I want to use the QJson library in my project. I've downloaded the tarball from the official site (probably need to mention that I'm under 64-bit Ubuntu 12.04). The INSTALL file has the following instructions
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=_preferred_path_ ..
make
make install
/sbin/ldconfig, if necessary
which I followed precisely. I've got the /include
, /lib
and share
folders of QJson added to my /usr/local
.
After that, I open my IDE (which is QtCreator), and make a test project with the following simple code:
#include <QVariant>
#include <qjson/serializer.h>
int main(int argc, char *argv[])
{
QJson::Serializer s;
QVariantMap map;
map["hello"] = QVariantList() <<"t1"<<"t2";
QByteArray json = s.serialize(map);
}
The #include
is handled fine, all the types are recognized, the auto-complete for the QJson classes works fine. However, when trying to compile, I'm getting this (full path removed for readability):
<...>/QJsonTest/main.cpp:15: undefined reference to `QJson::Serializer::Serializer()'
<...>/QJsonTest/main.cpp:18: undefined reference to `QJson::Serializer::serialize(QVariant const&)'
<...>/QJsonTest/main.cpp:18: undefined reference to `QJson::Serializer::~Serializer()'
<...>/QJsonTest/main.cpp:18: undefined reference to `QJson::Serializer::~Serializer()'
collect2: ld returned 1 exit status
What's the reason, and how do I make it work?
You are hitting linker (not compiler) errors. You need to add the path to your QJson library files with a -L
option