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. QT Projects Organization & Link Static Library
Forum Updated to NodeBB v4.3 + New Features

QT Projects Organization & Link Static Library

Scheduled Pinned Locked Moved Solved General and Desktop
subprojectlinklibrary
2 Posts 1 Posters 1.6k 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.
  • D Offline
    D Offline
    Dong
    wrote on 22 Jan 2016, 09:09 last edited by
    #1

    Hi All !

    I have a big project and I want to organize it by separate it in to multi projects

    This is the structure of my Projects Tree

    MyApplication (SubDirs)
        Framework (SubDirs)
            DynamicObjectCore (Statically Linked Library)
            Utilities (Statically Linked Library)
        Presentation (App)
        Services (SubDirs)
            GoogleServices (Statically Linked Library)
    

    I'm use "Add Library" Context Menu and this is generated code in my Presentation.pro

    # Link to Framework.DynamicObjectCore
    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Framework/DynamicObjectCore/release/ -lDynamicObjectCore
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../Framework/DynamicObjectCore/debug/ -lDynamicObjectCore
    else:unix: LIBS += -L$$OUT_PWD/../Framework/DynamicObjectCore/ -lDynamicObjectCore
    
    INCLUDEPATH += $$PWD/../Framework/DynamicObjectCore
    DEPENDPATH += $$PWD/../Framework/DynamicObjectCore
    
    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Framework/DynamicObjectCore/release/libDynamicObjectCore.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Framework/DynamicObjectCore/debug/libDynamicObjectCore.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Framework/DynamicObjectCore/release/DynamicObjectCore.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../Framework/DynamicObjectCore/debug/DynamicObjectCore.lib
    else:unix: PRE_TARGETDEPS += $$OUT_PWD/../Framework/DynamicObjectCore/libDynamicObjectCore.a
    
    # Link to Framework.Utilities
    # Link to Services.GoogleAdWordsService
    # Same as above
    

    in main.cpp I'm already include need class like this

    // Include from Framework.DynamicObjectCore
    #include "dynamicobject.h"
    #include "MetadataModel/formmetadata.h"
    // Include from Framework.Utilities
    #include "metadatahelper.h"
    
    int main(int argc, char *argv[])
    {
        ...
        //Load Form Metadata
        QString filePath = QCoreApplication::applicationDirPath()+"/Config/FormMetadata/FormMetadata.xml";
        FormMetaData formMetadata = MetadataHelper::GetFormMetaData(filePath);
    
        DynamicObject* dynamicObject = new DynamicObject();
        QVariant val = dynamicObject->property("Name");
    }
    
    

    MetadataHelper::GetFormMetaData is static function

    Why I get this ?
    error: undefined reference to `MetadataHelper::GetFormMetaData(QString)'

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dong
      wrote on 27 Jan 2016, 03:36 last edited by
      #2

      After few days searching on Google.
      I found the answer.

      The problem is the order you Link to Static Library.

      Dependency of my Projects is:
      Presentation << Utilities << DynamicObjectCore

      in Presentation.pro, I'm link to Static Link Library in this order

      # Link to DynamicObjectCore
      ...
      # Link to Utilities
      ...
      

      I thought that it will compile DynamicObjectCore first, then compile Utilities.
      But it wan't, and cause the compile error. "undefined reference to..."

      When i change the Link Order

      # Link to Utilities
      ...
      # Link to DynamicObjectCore
      ...
      

      And it work.

      1 Reply Last reply
      0

      1/2

      22 Jan 2016, 09:09

      • Login

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