Results 1 to 4 of 4

Thread: dll linking

  1. #1
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default dll linking

    I am having hard time to find a solution for this linking error:

    moc_TableView.obj : error LNK2001: unresolved external symbol "public: static
    struct QMetaObject const CModelViewList::staticMetaObject"
    (?staticMetaObject@CModelViewList@@2UQMetaObject@@ B)

    I am trying to link this against a DLL.

    Here's what I have defined for creating DLL


    #ifndef QTAP_EXPORT
    #define QTAP_EXPORT __declspec( dllexport )
    #endif

    I have declared QTAP_EXPORT for everyclass for exporting symbols. I start getting this problem once I moved the location of that particular file from one project to another. I have checked the moc files and all are created fine.

    thanks,

  2. #2
    Join Date
    Jul 2007
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dll linking

    Hi, i had the same problem.
    The solution i found is this:
    1) In your shared lib project create a .h file like this : ( My librarys name is PulzarLib )

    WindowsShit.h

    #include <QtCore/qglobal.h>

    #ifndef __PULZARLIB_WINDOWSSHIT_H__
    #define __PULZARLIB_WINDOWSSHIT_H__

    #ifdef Q_WS_WIN // Is the system shitdows ??
    #ifdef PULZARLIBEXP // Am i compiling my shared library ?
    # define PULZARLIB_EXPORT __declspec(dllexport) // if yes then export my classes
    # define prueba1 QString("DEFINIDO").toAscii() // test
    #else
    # define PULZARLIB_EXPORT __declspec(dllimport) // if not then import the classes
    # define prueba1 QString("NENE").toAscii() // test
    #endif
    #else
    #define PULZARLIB_EXPORT // if it is Linux empty this macro
    #endif

    #endif // __WINDOWSSHIT_H__

    2) make sure you pass to the compiler the PULZARLIBEXP flag or edit the Makefile.release in windows and add -DPULZARLIBEXP to de DEFINES variable :

    DEFINES = -DPULZARLIBEXP .....

    this tells the compilar that we are building our library so we must export our classes

    3) Add the defined macro to the definition of the classes that you want to export ( those that your application will use directly ) like this

    class PULZARLIB_EXPORT LoginGui : public QDialog

    4) in the header files of your application where you will use the library add :

    #include <WindowsShit.h>

    notice that since PULZARLIBEXP won't be defined in the application then PULZARLIB_EXPORT becomes __declspec(dllimport) , which imports the classes

    it seemed that you didnt import your classes if your application

    hope that help

    PD: sorry bad english

  3. The following user says thank you to berzeck for this useful post:

    Project25 (11th July 2007)

  4. #3
    Join Date
    Mar 2007
    Posts
    15
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: dll linking

    Thanks for reply. I will try tommorow morning. Do I need to add that my header file for instance PulzarLib.h to the project file(.pro) headers. According to error that I am getting is that TableView class in under Project B and CModelViewList class in under Project A. Project A iteslf itself is linking fine but when I try to build project B then I start getting linking error. Because TableView class is inherting CModelListView class/functions from Project A. I defined QTAP_EXPORT __declspec( dllexport ) macro in front of CModelViewList class like

    Project A

    class QTAP_EXPORT CModelViewList :ublic QObject, public....

    Project B

    class TableView :: public CModelViewList
    {
    Q_Object
    ---
    }



    moc_TableView.obj : error LNK2001: unresolved external symbol "public: static
    struct QMetaObject const CModelViewList::staticMetaObject"
    (?staticMetaObject@CModelViewList@@2UQMetaObject@@ B)

    Thanks,

  5. #4
    Join Date
    Jul 2007
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dll linking

    Hi, sorry for the late response.

    Addressing your questions :
    The header file explained in step 1 must be included just in the lib's .pro file and not in the apps .pro file.

    A second consideration : are you using mingw, qmake stack of tools under windows ?

    this is important because, for example, the macro Q_WS_WIN is just defined under qmake, if you use visual studio there must be another variables

    I strongly reccomend that you use mingw, qmake and qdevelop (IDE) so it is much easier to develop truly multiplataform apps ( at leaste i made my projects under linux and windows )

    hope that helps

Similar Threads

  1. static & dynamic linking
    By mickey in forum General Programming
    Replies: 6
    Last Post: 11th June 2010, 08:57
  2. Linking myLib with myApp
    By vermarajeev in forum Qt Programming
    Replies: 11
    Last Post: 20th February 2007, 13:51
  3. Statically Linking... everything
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 26th October 2006, 17:43
  4. 0xc0000005 when linking against lib
    By niko in forum Qt Programming
    Replies: 10
    Last Post: 8th March 2006, 08:55
  5. Replies: 4
    Last Post: 20th February 2006, 09:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.