Compilation error when using static ibrary .a file created with QT in Console APP
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 ..
Re: Compilation error when using static ibrary .a file created with QT in Console APP
Hi,
Are you using windows ?
if yes,
please change this line :
Code:
LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/libMyQTLib.a"
to
Code:
LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/" -lMyQTLib
Best regards,
Toto
Re: Compilation error when using static ibrary .a file created with QT in Console APP
Thanks Toto , it did solve the compilation issue mentioned below.
However i am facing some more compilation errors while using sbml library .
I have build libSBML library in Windows 7 machine with MinGW compiler.
However while using the built library inside my program (console application) i am getting linking errors.
I have build libSBML statically using below commands:
1) export CXXFLAGS="-DLIBSBML_STATIC -DLIBLAX_STATIC -I ./dependencies/include
/xercescâ€
2) ./configure --enable-static --with-xerces=./dependencies --prefix="/home/LABS
9/outputLibSbml/"
3) make LDFLAGS=-no-undefined
//////////////////////////////////main.cpp//////////////////////////
#include <sbml/SBMLTypes.h>
#include <sbml/common/extern.h>
int main(int argc, char *argv[])
{
SBMLDocument* document;
SBMLReader reader;
return 0;
}
///////////////////////////////////////
/////////////////////error ////////////////////////////////////////////
debug/main.o: In function `main':
D:\QTSamples\TestSBML-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/../TestSBML/main.cpp:20: undefined reference to `_imp___ZN10SBMLReaderC1Ev'D:\QTSamples\TestSBML-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/../TestSBML/main.cpp:22: undefined reference to `_imp___ZN10SBMLReaderD1Ev'D:\QTSamples\TestSBML-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/../TestSBML/main.cpp:22: undefined reference to `_imp___ZN10SBMLReaderD1Ev'collect2: ld returned 1 exit status
////////////////////////////////////////////////////////////////////////////////////
//////////////////TestSBML.pro/////////////////////////////
TARGET = TestSBML
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH +=../sbmlAll
LIBS+= -L"../sbmlAll/sbmllib" -lsbml
/////////////////////////////////////////////////////////////////////////////////////
Please let me know if any idea.
Thanks.
Quote:
Originally Posted by
myta212
Hi,
Are you using windows ?
if yes,
please change this line :
Code:
LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/libMyQTLib.a"
to
Code:
LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/" -lMyQTLib
Best regards,
Toto
Re: Compilation error when using static ibrary .a file created with QT in Console APP
That is a linker error. Linker errors are often the result of your LIBS variable being wrong. Either the path associated with the -L option or the name of the library is wrong.