Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I am unable to link to my own library created using 4.7.3(MinGW) compiler in Qt SDK 1.1.1 Windows

I am unable to link to my own library created using 4.7.3(MinGW) compiler in Qt SDK 1.1.1 Windows

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rupeshbhurke
    wrote on last edited by
    #1

    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/ -lTestLib

    SOURCES += 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 function main': 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 to TestLib::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 to TestLib::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'

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Use LIBS instead of QMAKE_LFLAGS_DEBUG.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rupeshbhurke
        wrote on last edited by
        #3

        Thank you for the reply!
        And what's more it worked like a charm!
        Thanks a ton!

        BR
        Rupesh

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved