I am unable to link to my own library created using 4.7.3(MinGW) compiler in Qt SDK 1.1.1 Windows
-
Hi,
I've created a sample test lib with test application. My lib project compiles fine however when I compile test application I get linker errors.
Somebody please tell me what seems to be the problem. Am I missing anything or have done anything wrong?Following is the code of Lib .pro & code, test app .pro & code and list of errors:
TestLib.pro
@
QT -= gui
TARGET = TestLib
TEMPLATE = lib
CONFIG += staticlib
SOURCES += TestLib.cpp
HEADERS += TestLib.h
@TestLib.h
@
#ifndef TESTLIB_H
#define TESTLIB_H
class TestLib {
public:
TestLib();
~TestLib();void t( int _t ); int t() const;
private:
int m_t;
};
#endif // TESTLIB_H
@TestLib.cpp
@
#include "TestLib.h"TestLib::TestLib() : m_t( 0 ) {}
TestLib::~TestLib() {}void TestLib::t( int _t ) { m_t = _t; }
int TestLib::t() const { return m_t; }
@Now test application files:
LibTest.pro
@
QT += core
QT -= gui
TARGET = LibTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QMAKE_LFLAGS_DEBUG += -L../TestLib-build-desktop/debug/ -lTestLibSOURCES += main.cpp
@main.cpp
@
#include <QtCore/QCoreApplication>
#include <iostream>
#include "../TestLib/TestLib.h"int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TestLib t;
std::cout << t.t();
t.t( 20 );
std::cout << t.t();
return a.exec();
}
@Upon compilation of test application, I get following errors:
debug/main.o: In functionmain': D:\Rups\LibTest-build-desktop/../LibTest/main.cpp:8: undefined reference to
TestLib::TestLib()'
D:\Rups\LibTest-build-desktop/../LibTest/main.cpp:9: undefined reference toTestLib::t() const' D:\Rups\LibTest-build-desktop/../LibTest/main.cpp:10: undefined reference to
TestLib::t(int)'
D:\Rups\LibTest-build-desktop/../LibTest/main.cpp:11: undefined reference toTestLib::t() const' D:\Rups\LibTest-build-desktop/../LibTest/main.cpp:12: undefined reference to
TestLib::~TestLib()'
D:\Rups\LibTest-build-desktop/../LibTest/main.cpp:12: undefined reference to `TestLib::~TestLib()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\LibTest.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project LibTest (target: Desktop)
When executing build step 'Make' -
Use LIBS instead of QMAKE_LFLAGS_DEBUG.
-
Thank you for the reply!
And what's more it worked like a charm!
Thanks a ton!BR
Rupesh