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. Building shared library with static components
Qt 6.11 is out! See what's new in the release blog

Building shared library with static components

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 727 Views 1 Watching
  • 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.
  • B Offline
    B Offline
    blackdiamond
    wrote on last edited by
    #1

    I have two algorithms that i am developing into dlls. They use some common code and so I am building a static library that both dll can use. When I compile the algorithm I get a bunch of LNK2019: unresolved external symbol errors. Also get some LNK2001: unresolved external symbol errors as well.

    My pro files are set up in such a way that they use pri files to allow certain settings.

    the static shared or common pro file is:

    @include(../options.pri)
    TEMPLATE = lib
    CONFIG += static

    INCLUDEPATH += .
    DEPENDPATH += $$INCLUDEPATH

    SOURCES +=
    *.cpp files\

    HEADERS +=
    *.h files...@

    My algorithm code pro files is :

    @include(../options.pri)

    QT -= gui

    TARGET = StaticAlgorithm
    TEMPLATE = lib
    CONFIG += shared

    include(../common/includeme.pri)

    INCLUDEPATH += .

    DEPENDPATH += $$INCLUDEPATH

    DEFINES += STATICALGORITHM_LIBRARY

    SOURCES += *.cpp files\

    HEADERS += *.h files\

    unix:!symbian {
    maemo5 {
    target.path = /opt/usr/lib
    } else {
    target.path = /usr/lib
    }
    INSTALLS += target
    }@

    My 3 pri files are the following:
    options.pri
    @CONFIG -= debug
    CONFIG += release

    CONFIG += silent

    DEFINES += USING_QT

    UI_DIR = .ui
    MOC_DIR = .moc

    win32 {

    QMAKE_CXXFLAGS += /MP

    QMAKE_CXXFLAGS += -D_SCL_SECURE_NO_WARNINGS

    } else {

    }

    exists( $$PWD/options.user ) {
    include( $$PWD/options.user )
    }

    OBJECTS_DIR = .obj/release
    debug { OBJECTS_DIR = .obj/debug }

    exists($$QMAKE_LIBDIR_QT/libQtGui.a) {
    DEFINES += QT_STATIC_LIB
    } else {
    DEFINES += QT_SHARED_LIB
    }
    @

    includeme.pri
    @LIB_NAME=common
    LIB_DIR=$$PWD

    include($$PWD/../PriFiles/includeme.template.pri)@

    template
    @INCLUDEPATH += $$LIB_DIR
    DEPENDPATH += $$LIB_DIR

    If an app is including this file (versus another lib),

    add the lib path for them:

    contains(TEMPLATE, app) {

    LIB_BUILD_DIR=
    win32 {
        LIB_BUILD_DIR=/release
        debug {
            LIB_BUILD_DIR=/debug
        }
    }
    
    QMAKE_LIBDIR += $$LIB_DIR$$LIB_BUILD_DIR
    
    win32 {
        PRE_TARGETDEPS += $$LIB_DIR$$LIB_BUILD_DIR/$${LIB_NAME}.lib
        LIBS           += $$LIB_DIR$$LIB_BUILD_DIR/$${LIB_NAME}.lib
    } else {
        PRE_TARGETDEPS += $$LIB_DIR$$LIB_BUILD_DIR/lib$${LIB_NAME}.a
        LIBS += -l$${LIB_NAME}
    }
    

    }@

    When I build the algorithm as a static library it compiles fine, but as soon as I try to make it a shared library I get the errors.

    1 Reply Last reply
    0

    • Login

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