Results 1 to 2 of 2

Thread: static library archiving question

  1. #1
    Join Date
    Jan 2007
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default static library archiving question

    Im building an application that uses 2 static archive libraries. ST1 and ST2.
    ST2 uses a function from ST1.

    The .pro file for ST2 looks something like:
    TEMPLATE = lib
    CONFIG += static
    LIBS += -L../ST1/release -lST1
    SOURCES += ST2.cpp
    HEADERS += ST2.h ST1.h
    DEPENDPATH += . ../ST1
    INCLUDPATH += . ../ST1

    I have an APP that uses ST1 and ST2, and I have the SOURCES HEADERS LIBS, etc set properly in the APP's project file, but when I compile, I get

    ../path/to/ST2.a(ST2.o):ST2.cpp: (.text+0x3616): undefined reference to functionFromST1().

    So to correct the undefined reference, I rebuilt ST2 and added ST1.cpp to ST2's project file's SOURCES. The result is that ar adds the ST1.o object file to the libST2.a archive.

    While this works in this particular case, I do not think it is correct to add the source cpp file from ST1 to ST2's project. My primary reason for this is that what if I only had the library and not the source cpp files?

    I am not certain, but I think the correct course of action here is to make APP see the ST1 function some other way or to add ST1 directly into the ST2 archive.

    APPs .pro file looks something like this:
    TEMPLATE = app
    LIBS += -L../ST1/release -lST1 -L../ST2/release -lST2
    SOURCES += APP.cpp
    HEADERS += APP.h ST1.h ST2.h
    DEPENDPATH += . ../ST1 ../ST2
    INCLUDPATH += . ../ST1 ../ST2

    Since both libraries are part of LIBS why do I get the undefined reference?

    Anybody care to shed some light on this for me?

    Thank you,
    ChasW

  2. #2
    Join Date
    Jan 2007
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: static library archiving question

    my apologies. i figured this out finally just after posting.

    the tip came from http://gcc.gnu.org/ml/gcc-help/2004-04/msg00106.html

    all i had to do is change the order of the LIBS from APP.

    Cheers,
    Chas

Similar Threads

  1. Generating a static and dynamic library
    By elcuco in forum Qt Programming
    Replies: 3
    Last Post: 20th August 2011, 11:46
  2. Wrap a static QT library inside an XPCOM component ?
    By Paul_Xul in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2010, 07:16
  3. Replies: 16
    Last Post: 23rd May 2008, 10:12
  4. Win32 qmake: building a static library
    By Amanda in forum Qt Programming
    Replies: 5
    Last Post: 8th November 2006, 19:32
  5. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52

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.