Results 1 to 3 of 3

Thread: Undefined reference to signal when linking static library

  1. #1
    Join Date
    May 2011
    Posts
    30
    Thanks
    1

    Default Re: Undefined reference to signal when linking static library

    Hi, all. I'm writing a dynamic library and an application that uses it.
    When I compile the library everything seems to be ok, no error messages. But when I compile the application, linker prints the following message:
    undefined reference to dbConnected(QString). dbConnected is a signal in my library.
    I have tried many things (qmake && make, generate & link *.prl) but the problem stays the same.

    Dynamic Library project file:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2012-07-31T02:34:49
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += sql
    8.  
    9. QT -= gui
    10.  
    11. TARGET = DatabaseTools
    12. TEMPLATE = lib
    13.  
    14. DEFINES += DATABASETOOLS_LIBRARY
    15.  
    16. SOURCES += DatabaseTools.cpp \
    17. DatabaseObject.cpp \
    18. DatabaseQuery.cpp \
    19. DatabaseMutex.cpp \
    20. DatabaseQueryResult.cpp \
    21. DatabaseThread.cpp \
    22. DatabaseQueue.cpp \
    23. DatabaseHandle.cpp
    24.  
    25. HEADERS += DatabaseTools_global.h \
    26. DatabaseTools.h \
    27. DatabaseObject.h \
    28. DatabaseQuery.h \
    29. DatabaseMutex.h \
    30. DatabaseQueryResult.h \
    31. DatabaseThread.h \
    32. DatabaseQueue.h \
    33. DatabaseHandle.h
    34.  
    35. INCLUDEPATH += /usr/include/mysql
    36. LIBS += -lmysqlclient
    37.  
    38. DLLDESTDIR = ../Build
    39. DESTDIR = ../Build
    40. CONFIG += create_prl
    To copy to clipboard, switch view to plain text mode 

    Class header file:
    Qt Code:
    1. #ifndef DATABASETOOLS_H
    2. #define DATABASETOOLS_H
    3.  
    4. #include "DatabaseTools_global.h"
    5. #include <QObject>
    6. #include <QPointer>
    7. #include <QStringList>
    8. #include <QMap>
    9. #include <QTimer>
    10.  
    11. #include "DatabaseHandle.h"
    12. #include "DatabaseQueue.h"
    13. #include "DatabaseThread.h"
    14. #include "DatabaseQuery.h"
    15. #include "DatabaseObject.h"
    16.  
    17.  
    18. class DATABASETOOLSSHARED_EXPORT DatabaseTools : public QObject
    19. {
    20. static QMap<QString, QPointer<DatabaseTools> > PointersMap;
    21.  
    22. QTimer* UpdateTimer;
    23. DatabaseHandle DbHandle;
    24. DatabaseQueue DbQueue;
    25.  
    26. QString SessionUserName, SessionPassword;
    27.  
    28. bool IsDbEmpty;
    29. QString DbVersion;
    30. QString SupportedVersion;
    31. QStringList UsersNamesList;
    32. QString SessionId;
    33.  
    34. QString ConnectionName;
    35.  
    36. DatabaseTools (QString connection_name);
    37.  
    38. public:
    39.  
    40. static QPointer<DatabaseTools>& getInstace(QString connection_name);
    41. static void setAllMultiThreaded (bool multithreaded_operations);
    42.  
    43. void setMultiThreaded (bool multithreaded_operations);
    44.  
    45. void connect ();
    46. void close ();
    47. void login ();
    48. void logout ();
    49. void suspend ();
    50.  
    51. bool isConnected ();
    52.  
    53. QString connectionName ();
    54.  
    55. void setDbAuthParams (QString host_name, QString user_name, QString password);
    56. void setDbPort (int port);
    57. void setSessionAuthParams (QString user_name, QString password);
    58.  
    59. signals:
    60.  
    61. void dbConnected (QString connection_name);
    62. void dbClosed (QString connection_name);
    63. void dbOperating (QString connection_name);
    64. void dbReady (QString connection_name);
    65.  
    66. private slots:
    67.  
    68. void DatabaseThread_finished (DatabaseThread* thread);
    69. void DatabaseObject_connected ();
    70. void DatabaseObject_closed ();
    71.  
    72. };
    73.  
    74.  
    75. #endif // DATABASETOOLS_H
    To copy to clipboard, switch view to plain text mode 

    Application project file:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2012-07-30T20:05:45
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui sql
    8.  
    9. TARGET = FitnessCenter-Application
    10. TEMPLATE = app
    11.  
    12. LIBS += -L/home/zzz9/Projects/FitnessCenter/Build -lDatabaseTools
    13.  
    14. SOURCES += main.cpp\
    15. MainWindow.cpp \
    16. SetupWizard.cpp \
    17. ../Widgets/DatabaseStateWidget.cpp
    18.  
    19. HEADERS += MainWindow.h \
    20. SetupWizard.h \
    21. ../Widgets/DatabaseStateWidget.h
    22.  
    23. FORMS += MainWindow.ui \
    24. SetupWizard.ui \
    25. ../Widgets/DatabaseStateWidget.ui
    26.  
    27. RESOURCES += \
    28. ../Pixmaps/Pixmaps.qrc
    29.  
    30. OTHER_FILES += \
    31. Напоминания.txt
    32.  
    33. DESTDIR = ../Build
    34.  
    35. CONFIG += link_prl
    To copy to clipboard, switch view to plain text mode 


    Added after 19 minutes:


    application and lib are in debug
    Last edited by zzz9; 11th August 2012 at 15:39.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to signal when linking static library

    You forgot the Q_OBJECT macro in the declaration of DatabaseTools.

  3. #3
    Join Date
    May 2011
    Posts
    30
    Thanks
    1

    Default Re: Undefined reference to signal when linking static library

    Oh, great! Thanks.

Similar Threads

  1. Undefined reference to signal
    By chinalski in forum Qwt
    Replies: 8
    Last Post: 29th July 2012, 19:05
  2. Undefined reference to my signal
    By tomek in forum Newbie
    Replies: 9
    Last Post: 1st December 2011, 07:14
  3. Undefined reference in static binding in Linux
    By gcubar in forum Installation and Deployment
    Replies: 9
    Last Post: 28th February 2011, 15:20
  4. QT and my own shared library, undefined reference to ...
    By webquinty in forum General Programming
    Replies: 4
    Last Post: 4th March 2009, 15:09
  5. Linking error: libQtNetwork.so: undefined reference to `_freeifaddrs'
    By dacla in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 21st April 2008, 22:26

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.