[Qt-interest] Static Lib dependecy/linking problem...

Stephen Jackson spjackson42 at gmail.com
Tue Oct 13 11:26:38 CEST 2009


On Tue, Oct 13, 2009 at 1:45 AM, Dan O'Connor wrote:
> I am using multiple libraries in my project, and I've noticed that
> functions or methods which are not called in the final project are not
> being included for linking. Below I've attempted to reproduce a
> concrete example of my problem:
>

[snip]

>
> /usr/bin/ld: Undefined symbols:
> TestFunctions::DoSomethingToAnInt(int&)
> collect2: ld returned 1 exit status
>
> By adding the following lines to the main function linking completes
> successfully:
>
> int a = 0;
> TestFunctions::DoSomethingToAnInt( a );
>
> What is the correct way to create libraries which can be used by other
> libraries?
>

In testlibtwo.pro your LIBS line is pointless because linking does not
place place when creating a static library.

In testprogram.pro you need to change the order of the libraries, i.e.
LIBS += -L../testlibtwo -ltestlibtwo \
   -L../testlibone -ltestlibone

This is because testlibone defines symbols that are used by
testlibtwo. Each library is processed in turn and code is pulled in
only for those symbols that the linker knows are needed at that point
in time.

Although you are using qmake, this isn't really a Qt issue - it is the
same for any build system.

-- 
HTH,

Stephen Jackson



More information about the Qt-interest-old mailing list