I am using QT Creator 2.4.1 on WindoI w7 with MinGW compiler.
1) Created MyLib.a using static library template provided by QT IDE.
2) Create MyApp.exe console application with QT.
3) Did below setting in MyApp.pro file to link the library
INCLUDEPATH +=../MyQTLib
LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/libMyQTLib.a"
4) Created object of the class defined in library and called the function.
5) While compiling MyApp.pro i am getting below error:
D:\QTSamples\MyQTApp-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/../MyQTApp/main.cpp:10: undefined reference to `MyQTLib::MyQTLib()'
D:\QTSamples\MyQTApp-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/../MyQTApp/main.cpp:12: undefined reference to `MyQTLib::getNumber()'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug\MyQTApp.exe] Error
6) I followed steps in http://qt-project.org/wiki/How_to_cr...an_application still getting the error.
Details :
////////////////////////////////////////myqtlib.cpp////////////////////////////////
#include "myqtlib.h"
MyQTLib::MyQTLib()
{
}
int MyQTLib::getNumber()
{
return 100;
}
//////////////////////////main.cpp///////////////////////////////
#include <QtCore/QCoreApplication>
#include <iostream>
#include <myqtlib.h>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyQTLib b;
cout << "Hello World" << "number" << b.getNumber()<<endl;
return a.exec();
}
////////////////MyQTLib.pro/////////////////////////////
QT -= core gui
TARGET = MyQTLib
TEMPLATE = lib
CONFIG += staticlib
SOURCES += myqtlib.cpp
HEADERS += myqtlib.h
unix:!symbian {
maemo5 {
target.path = /opt/usr/lib
} else {
target.path = /usr/lib
}
INSTALLS += target
}
//////////////////////MyQtApp.pro////////////////////
QT += core
QT -= gui
TARGET = MyQTApp
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH +=../MyQTLib
LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/libMyQTLib.a"
SOURCES += main.cpp
//////////////////////////////////////////
Please help ..
Bookmarks