Reputation: 1181
I've followed the instructions in the link below (and some threads here) http://qt-project.org/doc/qt-4.8/sharedlibrary.html
I'm building a project successfully, but I only see the usual objects and the final binary after compilation. Nothing that looks like a library at all.
Ideas?
MyWidget_global.h
#ifndef MY_WIDGET_GLOBAL_H
#define MY_WIDGET_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(MY_WIDGET_LIBRARY)
# define MY_WIDGET_EXPORT Q_DECL_EXPORT
#else
# define MY_WIDGET_IMPORT Q_DECL_IMPORT
#endif
#endif
The project file
DEFINES += MY_WIDGET_LIBRARY
# Input
HEADERS += MyWidget_global.h \
MyWidget.h
# Input
SOURCES += main.cpp \
MyWidget.cpp
And finally the header of the actual class
#ifndef MY_WIDGET_H
#define MY_WIDGET_H
#include "MyWidget_global.h"
class MY_WIDGET_EXPORT MyWidget
{
public:
MyWidget();
// Snip
};
#endif
Upvotes: 0
Views: 693
Reputation: 7692
Qt comes with a series of predefined project templates. Directly from the documentation here:
The TEMPLATE variable is used to define the type of project that will be built. If this is not declared in the project file, qmake assumes that an application should be built, and will generate an appropriate Makefile (or equivalent file) for the purpose.
Hence, in your case, QMake assumes that an application was meant to be build. Adding the right template solves the problem, i.e.
TEMPLATE = lib
is the solution. Indeed lib
is the correct template to create an output makefile for a library.
See here for a correct creation of a library and its addition to a project.
Upvotes: 1