I am attempting to build a simple dll hello world example. I have build qt 4.7.0 for static linking by doing this on the command line:
C:\Qt\4.7.0> configure -static -release -no-exceptions -nomake examples -nomake demos
C:\Qt\4.7.0> make sub-src
C:\Qt\4.7.0> configure -static -release -no-exceptions -nomake examples -nomake demos
C:\Qt\4.7.0> make sub-src
To copy to clipboard, switch view to plain text mode
Here is my sample .pro file
TEMPLATE = lib
TARGET = helloworld
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += dll
# Input
HEADERS += helloworld.h
SOURCES += helloworld.cpp
TEMPLATE = lib
TARGET = helloworld
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += dll
# Input
HEADERS += helloworld.h
SOURCES += helloworld.cpp
To copy to clipboard, switch view to plain text mode
here is my example helloworld.cpp
#include "helloworld.h"
#include <stdio.h>
HelloWorld
::HelloWorld(QObject *parent
) :{
}
void HelloWorld::sayHello() {
printf("Hello World!\n");
done();
}
#include "helloworld.h"
#include <stdio.h>
HelloWorld::HelloWorld(QObject *parent) :
QObject(parent)
{
}
void HelloWorld::sayHello() {
printf("Hello World!\n");
done();
}
To copy to clipboard, switch view to plain text mode
and the header...
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
#include <QObject>
{
Q_OBJECT
public:
explicit HelloWorld
(QObject *parent
= 0);
signals:
void done();
public slots:
void sayHello();
};
#endif // HELLOWORLD_H
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
#include <QObject>
class HelloWorld : public QObject
{
Q_OBJECT
public:
explicit HelloWorld(QObject *parent = 0);
signals:
void done();
public slots:
void sayHello();
};
#endif // HELLOWORLD_H
To copy to clipboard, switch view to plain text mode
when I try to compile as dll, I get the errors shown below. Any Ideas?
C:\projects\qt\helloworld>qmake
C:\projects\qt\helloworld>make release
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `C:/projects/qt/helloworld'
g++ -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -shared -Wl,--out-implib,release\libh
elloworld.a -o release\helloworld.dll release/helloworld.o release/moc_helloworld.o -L"c:\Qt\4.7.0\lib" -lQtGui -lgdi32 -lcomdlg32 -lo
leaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32
Creating library file: release\libhelloworld.a
release/helloworld.o:helloworld.cpp:(.text+0x16): undefined reference to `_imp___ZN7QObjectC2EPS_'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x4d): undefined reference to `_imp___ZN7QObject11qt_metacastEPKc'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x8e): undefined reference to `_imp___ZN11QMetaObject8activateEP7QObjectPKS_iPPv'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0xb9): undefined reference to `_imp___ZN7QObject11qt_metacallEN11QMetaObject4CallEiP
Pv'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x100): undefined reference to `_imp___ZN7QObject16staticMetaObjectE'
release/moc_helloworld.o:moc_helloworld.cpp:(.text$_ZN10HelloWorldD1Ev[HelloWorld::~HelloWorld()]+0x10): undefined reference to `_imp__
_ZN7QObjectD2Ev'
release/moc_helloworld.o:moc_helloworld.cpp:(.text$_ZN10HelloWorldD0Ev[HelloWorld::~HelloWorld()]+0x15): undefined reference to `_imp__
_ZN7QObjectD2Ev'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\helloworld.dll] Error 1
mingw32-make[1]: Leaving directory `C:/projects/qt/helloworld'
mingw32-make: *** [release] Error 2
C:\projects\qt\helloworld>qmake
C:\projects\qt\helloworld>make release
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `C:/projects/qt/helloworld'
g++ -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -shared -Wl,--out-implib,release\libh
elloworld.a -o release\helloworld.dll release/helloworld.o release/moc_helloworld.o -L"c:\Qt\4.7.0\lib" -lQtGui -lgdi32 -lcomdlg32 -lo
leaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32
Creating library file: release\libhelloworld.a
release/helloworld.o:helloworld.cpp:(.text+0x16): undefined reference to `_imp___ZN7QObjectC2EPS_'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x4d): undefined reference to `_imp___ZN7QObject11qt_metacastEPKc'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x8e): undefined reference to `_imp___ZN11QMetaObject8activateEP7QObjectPKS_iPPv'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0xb9): undefined reference to `_imp___ZN7QObject11qt_metacallEN11QMetaObject4CallEiP
Pv'
release/moc_helloworld.o:moc_helloworld.cpp:(.text+0x100): undefined reference to `_imp___ZN7QObject16staticMetaObjectE'
release/moc_helloworld.o:moc_helloworld.cpp:(.text$_ZN10HelloWorldD1Ev[HelloWorld::~HelloWorld()]+0x10): undefined reference to `_imp__
_ZN7QObjectD2Ev'
release/moc_helloworld.o:moc_helloworld.cpp:(.text$_ZN10HelloWorldD0Ev[HelloWorld::~HelloWorld()]+0x15): undefined reference to `_imp__
_ZN7QObjectD2Ev'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\helloworld.dll] Error 1
mingw32-make[1]: Leaving directory `C:/projects/qt/helloworld'
mingw32-make: *** [release] Error 2
To copy to clipboard, switch view to plain text mode
Bookmarks