Results 1 to 4 of 4

Thread: Compilation error when using static ibrary .a file created with QT in Console APP

  1. #1
    Join Date
    Oct 2013
    Posts
    2
    Platforms
    Unix/X11 Windows

    Default 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 ..

  2. #2
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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 :
    Qt Code:
    1. LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/libMyQTLib.a"
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/" -lMyQTLib
    To copy to clipboard, switch view to plain text mode 

    Best regards,

    Toto

  3. #3
    Join Date
    Oct 2013
    Posts
    2
    Platforms
    Unix/X11 Windows

    Default 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 View Post
    Hi,
    Are you using windows ?
    if yes,
    please change this line :
    Qt Code:
    1. LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/libMyQTLib.a"
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. LIBS+= -L"../MyQTLib-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug/debug/" -lMyQTLib
    To copy to clipboard, switch view to plain text mode 

    Best regards,

    Toto

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.

Similar Threads

  1. qvalidator error on static msvc2010 compilation
    By stef13013 in forum Installation and Deployment
    Replies: 0
    Last Post: 20th September 2012, 00:08
  2. Compilation Error , Can't find lib file.
    By vijaydandur in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2011, 06:54
  3. Error in static compilation of Qt 2010.05!
    By elton.lika in forum Newbie
    Replies: 5
    Last Post: 26th January 2011, 22:37
  4. cannot compile QT 4.6 as static - uic3 error stops compilation
    By rucs_hack in forum Installation and Deployment
    Replies: 3
    Last Post: 27th June 2010, 06:35
  5. Replies: 3
    Last Post: 27th December 2008, 20:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.