Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Undefined reference problem
Forum Update on Monday, May 27th 2025

[Solved] Undefined reference problem

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 22.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zveljkovic
    wrote on 24 Nov 2010, 13:25 last edited by
    #1

    Hi. I am making application that will use shared libraries. I have problem building the shared library. In main app (exe) i have this header and according cpp file.

    @
    #ifndef MENUNODE_H
    #define MENUNODE_H

    #include <QString>
    #include <QList>
    #include <QLabel>
    #include "ActionResult.h"

    namespace Core
    {
    namespace UI
    {
    class MenuNode : public QLabel
    {
    Q_OBJECT
    public:
    explicit MenuNode(QWidget* Parent = 0);
    virtual ~MenuNode();
    QString Name;
    QList<MenuNode*> Nodes;
    virtual ActionResult Action();
    };
    }
    }

    #endif // MENUNODE_H
    @

    In shared library i have class that will be exported in its own cpp and h files. There is also a class that is used by this shared class. Here is its definition.

    @
    #ifndef ROOTSPEECH_H
    #define ROOTSPEECH_H

    #include <QString>
    #include <QList>
    #include "NeuroCommunicator/Core/UI/MenuNode.h"

    namespace Core
    {
    namespace UI
    {
    class RootSpeech: public MenuNode
    {
    Q_OBJECT
    public:
    RootSpeech(QWidget* parent = 0);
    ~RootSpeech();
    QString p;
    };
    }
    }

    #endif // ROOTSPEECH_H
    @

    and cpp file

    @
    #include "RootSpeech.h"

    namespace Core
    {
    namespace UI
    {
    RootSpeech::RootSpeech(QWidget* parent):MenuNode(parent){p = "asdf";}
    RootSpeech::~RootSpeech(){}
    }
    }
    @

    Now the problem is:
    @
    debug/RootSpeech.o: In function `RootSpeech':

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:8: undefined reference to `Core::UI::MenuNode::MenuNode(QWidget*)'

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:11: undefined reference to `Core::UI::MenuNode::~MenuNode()'

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:8: undefined reference to `Core::UI::MenuNode::MenuNode(QWidget*)'

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:11: undefined reference to `Core::UI::MenuNode::~MenuNode()'

    debug/RootSpeech.o: In function `~RootSpeech':

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:16: undefined reference to `Core::UI::MenuNode::~MenuNode()'

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:16: undefined reference to `Core::UI::MenuNode::~MenuNode()'

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:16: undefined reference to `Core::UI::MenuNode::~MenuNode()'

    D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:16: undefined reference to `Core::UI::MenuNode::~MenuNode()'

    debug/RootSpeech.o:D:!Projekat\Speech-build-desktop/../Speech/RootSpeech.cpp:16: more undefined references to `Core::UI::MenuNode::~MenuNode()' follow

    debug/moc_RootSpeech.o:D:!Projekat\Speech-build-desktop/debug/moc_RootSpeech.cpp:59: undefined reference to `Core::UI::MenuNode::qt_metacast(char const*)'

    debug/moc_RootSpeech.o:D:!Projekat\Speech-build-desktop/debug/moc_RootSpeech.cpp:64: undefined reference to `Core::UI::MenuNode::qt_metacall(QMetaObject::Call, int, void**)'

    debug/moc_RootSpeech.o:moc_RootSpeech.cpp:(.rdata+0x0): undefined reference to `Core::UI::MenuNode::staticMetaObject'

    debug/moc_RootSpeech.o:moc_RootSpeech.cpp:(.rdata$_ZTVN4Core2UI10RootSpeechE[vtable for Core::UI::RootSpeech]+0xe8): undefined reference to `Core::UI::MenuNode::Action()'

    collect2: ld returned 1 exit status
    @

    What I have tried so far: Run qmake from build then rebuild, including app.exe as lib, Q_DECLARE_INTERFACE, adding menuNode.h to .pro file... (can't remember any more).

    System is Windows 7 x64.

    Any help?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on 24 Nov 2010, 13:29 last edited by
      #2

      Do you use @Q_DECL_EXPORT@ and @Q_DECL_IMPORT@ ?

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zveljkovic
        wrote on 24 Nov 2010, 13:31 last edited by
        #3

        I tried that too but with no success. Ill try again, just tell me where to put it. (I think I tried both on MenuNode class but it didnt work)

        EDIT: On Q_DECL_EXPORT on MenuNode i got same errors. On Q_DECL_IMPORT i got errors on MenuNode.cpp and moc files.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zveljkovic
          wrote on 24 Nov 2010, 13:42 last edited by
          #4

          I tried adding CORESHARED_EXPORT to MenuNode and adding this file but ain't working (also added define to .pro file):
          @
          #ifndef CORE_GLOBAL_H
          #define CORE_GLOBAL_H

          #include <QtCore/qglobal.h>

          #if defined(CORE_LIBRARY)

          define CORESHARED_EXPORT Q_DECL_EXPORT

          #else

          define CORESHARED_EXPORT Q_DECL_IMPORT

          #endif

          #endif // CORE_GLOBAL_H
          @

          Same errors (after switching Q_DECL... still errors).

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on 24 Nov 2010, 14:08 last edited by
            #5

            Could you show us your .pro file please.

            As far as I understood your text an source code you are linking a shared lib against an app.exe (i.e. you have a shared lib that uses code that is defined in an exe)?

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on 24 Nov 2010, 14:29 last edited by
              #6

              Hi,
              it is not possible to have the base class in the main executable and a derived class in a shared library.
              If you want to have the derived class in the shared library (class RootSpeech: public MenuNode) you have to put the base class also in a shared library (the same or another lib you also reference in the there).
              An other thing is, if you use static libraries, but the you can put everything directly into the exe :-)

              So your problem is not a problem of exporting, it's more a problem of putting the right stuff in the right binary.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zveljkovic
                wrote on 24 Nov 2010, 14:40 last edited by
                #7

                Here's my pro of shared library.
                @
                CONFIG += debug_and_release build_all
                CONFIG(release){ DESTDIR = ../build-release/plugins }
                CONFIG(debug){ DESTDIR = ../build-debug/plugins }

                QT += core gui xml
                TARGET = Speech
                TEMPLATE = lib
                INCLUDEPATH += ../

                DEFINES += SPEECH_LIBRARY
                SOURCES += Speech.cpp
                RootSpeech.cpp
                HEADERS += Speech.h
                Speech_global.h
                RootSpeech.h
                @

                For Gerolf answer I got it, and i think that will solve the problem. Currently I dont have time to test it, so I will mark thread with [Solved] and if i still have problems i will re edit this one.

                Thanks for help!

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alexander
                  wrote on 24 Nov 2010, 14:47 last edited by
                  #8

                  where define CORE_LIBRARY in the .pro file?

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    IrQX
                    wrote on 25 Nov 2010, 04:43 last edited by
                    #9

                    add to pro fie: @DEFINES += CORE_LIBRARY@

                    1 Reply Last reply
                    0

                    1/9

                    24 Nov 2010, 13:25

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved