PDA

View Full Version : static library archiving question



ChasW
4th February 2007, 09:14
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

ChasW
4th February 2007, 09:38
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