Including a self-made library into another project

  • Hi.
    I'm trying to create a program with one library and one executable that invokes that library.

    At first, I've created one folder for the application, and then three subfolders, one for a test executable project, one for the library project and one that's the path in which both library and executable are copied.

    |- bin
    |- MyLibrary
    | |- MyLibrary <== .pro and sources
    | |- MyLibrary-build-desktop
    |- TestApp
    | |- TestApp <== .pro and sources
    | |- TestApp-build-desktop

    This is the .pro of the library

    @QT -= gui
    TARGET = MyLibrary
    TEMPLATE = lib

    SOURCES += mylibrary.cpp
    HEADERS += mylibrary.h
    MyLibrary_global.h \

    Copying to destination folder

    DESTDIR = ../../bin[/CODE]

    This one is the .pro of the test application
    [CODE]QT += core
    QT -= gui
    TARGET = TestApp
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app
    SOURCES += main.cpp

    MyLibrary Library

    LIBS += -L../../bin/
    INCLUDEPATH += ../../MyLibrary/MyLibrary

    Copying to destination folder

    DESTDIR = ../../bin@

    When I compile the library, it's successfully copied into the bin directory.

    If I include the mylibrary.h header into the test application, it finds it and it compiles.
    But, if I try to use the class defined in my library

    @#include <QtCore/QCoreApplication>

    #include "mylibrary.h"

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    MyLibraryClass<qint32> xTest (1,1,1);
    return a.exec&#40;&#41;;


    I obtain the error:

    [QUOTE]main.cpp:(.text+0x39): undefined reference to `MyLibraryClass<int>::MyLibraryClass(int, int, int)'[/QUOTE]

    I'd like to know where's the error, and how can I compile successfully the executable.

    Thanks in advance for your replies.

  • LIBS += -L../../bin/ -lMyLibrary

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.