Compiling QJson statically into Qt Application (multiple declaration errors)
Has anyone had success compiling QJson statically into an application? I am t开发者_开发问答rying to use QJson statically in my Qt application (Windows/Mac), meaning I'm trying to use the source files directly rather than compiling a DLL and using it. Is this possible? My program is producing lots of errors when I attempt to do it, mostly "multiple declaration" errors. They are seemingly related to having a method structure like this:
SerializerRunnable::SerializerRunnable(QObject* parent)
: QObject(parent),
QRunnable(),
d(new Private)
{
qRegisterMetaType<QVariant>("QVariant");
}
SerializerRunnable::~SerializerRunnable()
{
delete d;
}
Any ideas would be appreciated.
Thanks,
Code that's compiled into a DLL needs to export the functions and classes that it wants to expose to the outside world linking to it at runtime.
In this particular case that magic happens in qjson_export.h
:
#ifndef QJSON_EXPORT_H
#define QJSON_EXPORT_H
#include <QtCore/qglobal.h>
#ifndef QJSON_EXPORT
# if defined(QJSON_MAKEDLL)
/* We are building this library */
# define QJSON_EXPORT Q_DECL_EXPORT
# else
/* We are using this library */
# define QJSON_EXPORT Q_DECL_IMPORT
# endif
#endif
#endif
If you don't have DEFINES += QJSON_MAKEDLL
in your .pro
file then the compiler assumes that you are using a DLL, rather than compiling code, and gets confused when code that is marked as "defined elsewhere" by Q_DECL_EXPORT
is, in fact, right there, and stupidly assumes it's being defined multiple times.
I hope that makes sense. :P
精彩评论