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.
APP
|
|- bin
|- MyLibrary
| |- MyLibrary <== .pro and sources
| |- MyLibrary-build-desktop
|- TestApp
| |- TestApp <== .pro and sources
| |- TestApp-build-desktopThis is the .pro of the library
@QT -= gui
TARGET = MyLibrary
TEMPLATE = lib
DEFINES += MYLIBRARY_LIBRARYSOURCES += 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_bundleTEMPLATE = app
SOURCES += main.cppMyLibrary Library
LIBS += -L../../bin/libMyLibrary.so
INCLUDEPATH += ../../MyLibrary/MyLibraryCopying 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();
}@
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