[Interest] Problem creating a dll that uses Qt (mingw)

erick oliveira da silva eosilva2000 at ig.com.br
Mon Jan 16 18:44:24 CET 2012


Hallo Thales, I included the qmake and library directories in PATH but
unfortunatelly nothing changed. Thanks anyway.

Thiago, sorry, but I am not sure if I understood correctly your sugestion:
so, I tried to build my dll (that export functions that have several Qt
functions and objects) in a different directory using qmake macro DESTDIR.
Unfortunatelly I got the same errors. Thanks for you answer.

Here is a simple example that also doesn't work:

---- qtdll.pro  -------------------------------

QT -= gui
QT *= core

TEMPLATE = lib
CONFIG *= qt dll release

DEFINES += BUILD_DLL

CONFIG(debug, debug|release) {
    DESTDIR = ./binaries_debug
    } else {
    DESTDIR = ./binaries_release
    }

SOURCES = dllfct.cpp

HEADERS = dllfct.h

--- dllfct.h --------------------------------------

#ifdef BUILD_DLL
// the dll exports
#define EXPORT __declspec(dllexport)
#else
// the exe imports
#define EXPORT __declspec(dllimport)
#endif

// function to be imported/exported
EXPORT void tstfunc (void);

-----------------------------------------------------

---- dllfct.cpp ----------------------------------

#include <stdio.h>
#include <QString>
#include "dllfct.h"

EXPORT void tstfunc (void)
{
    QString a("Hello");
    QString b("World");
    a.append(" ");
    a.append(b);
    a.append("\n");
   printf (a.toAscii());
}

----------------------------

Here is the compiler output:

D:\dllmingw\qt>qmake qtdll.pro

D:\dllmingw\qt>mingw32-make -f Makefile.Release

g++ -c -O2 -Os -momit-leaf-frame-pointer -frtti -fno-exceptions -Wall
-DUNICODE
-DQT_LARGEFILE_SUPPORT -DQT_STATIC_BUILD -DBUILD_DLL -DQT_DLL -DQT_NO_DEBUG
-DQT
_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT
-DQT_HAVE
_SSE2 -DQT_THREAD_SUPPORT -I"..\..\qt_static_4.7.4\include\QtCore"
-I"..\..\qt_s
tatic_4.7.4\include" -I"..\..\qt_static_4.7.4\include\ActiveQt" -I"release"
-I".
.\..\qt_static_4.7.4\mkspecs\default" -o release\dllfct.o dllfct.cpp
In file included from dllfct.cpp:3:
dllfct.h:1:1: warning: "BUILD_DLL" redefined
<command-line>: warning: this is the location of the previous definition
g++ -static -static-libgcc -Wl,-s -shared
-Wl,--out-implib,.\binaries_release\li
bqtdll.a -o binaries_release\qtdll.dll release/dllfct.o
-L"d:\qt_static_4.7.4\l
ib" -lQtCore -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32
-lkernel32
Creating library file: .\binaries_release\libqtdll.a
release/dllfct.o:dllfct.cpp:(.text+0x18): undefined reference to
`_imp___ZN7QStr
ing16fromAscii_helperEPKci'
release/dllfct.o:dllfct.cpp:(.text+0x54): undefined reference to
`_imp___ZN7QStr
ing6appendERKS_'
release/dllfct.o:dllfct.cpp:(.text+0x74): undefined reference to
`_imp___ZNK7QSt
ring7toAsciiEv'
release/dllfct.o:dllfct.cpp:(.text+0x96): undefined reference to
`_imp___Z5qFree
Pv'
release/dllfct.o:dllfct.cpp:(.text+0xaf): undefined reference to
`_imp___ZN7QStr
ing4freeEPNS_4DataE'
release/dllfct.o:dllfct.cpp:(.text+0xc8): undefined reference to
`_imp___ZN7QStr
ing4freeEPNS_4DataE'
release/dllfct.o:dllfct.cpp:(.text$_ZN7QString6appendEPKc[QString::append(char
c
onst*)]+0x1e): undefined reference to `_imp___ZN7QString9fromAsciiEPKci'
release/dllfct.o:dllfct.cpp:(.text$_ZN7QString6appendEPKc[QString::append(char
c
onst*)]+0x2f): undefined reference to `_imp___ZN7QString6appendERKS_'
release/dllfct.o:dllfct.cpp:(.text$_ZN7QString6appendEPKc[QString::append(char
c
onst*)]+0x4b): undefined reference to `_imp___ZN7QString4freeEPNS_4DataE'
collect2: ld returned 1 exit status
mingw32-make: *** [binaries_release\qtdll.dll] Error 1

Best Regards,
Erick


2012/1/16 Thiago Macieira <thiago at kde.org>

> On Monday, 16 de January de 2012 15.52.44, erick oliveira da silva wrote:
> > Hi,
> >
> > I am new with qt programming using mingw.
> >
> > I have compiled Qt 4.7.4 statically with gcc(mingw) version  4.4.0 at
> > windows vista 32 bits, following the instructions in this page:
> >
> http://developer.qt.nokia.com/wiki/How_to_build_a_static_Qt_version_for_Wind
> > ows_with_gcc
> >
> > I can build static libraries and qt applications without any problem, but
> > when I try to build a shared library(dll) that uses qt, I get several
> > "undefined reference" linking errors in qt functions form QString,
> QDialog,
> > etc...
>
> Please make sure that you have a completely separate build directory for
> the
> DLL build. You can share the sources with the static build, provided you
> did
> not build the static one in the sources.
>
> The cleanest way is to make them completely separate.
>
> > The pro files I created till now build shared libraries in gcc linux
> > without any problem, but not in gcc windows(mingw). Do I need to define a
> > special qmake variable in the pro file to build suscessfully a qt dll in
> > gcc at windows?
>
> No, the same .pro file should be enough, provided you use the right qmake.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>   Software Architect - Intel Open Source Technology Center
>      PGP/GPG: 0x6EF45358; fingerprint:
>      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120116/d88a984a/attachment.html>


More information about the Interest mailing list