[Qt-interest] Static Lib dependecy/linking problem...
Patrick Vollebregt
jeet.nl at gmail.com
Tue Oct 13 12:45:46 CEST 2009
Hi,
First you should change:
#include "testfunctions.h"
into:
#include <testfunctions.h>
in your testlibtwo and testprogram.
Second, I have an example which I use and works, I refer directly to my
libraries:
win32:LIBS+=../CCSSH/debug/libCCSSH.a
win32:POST_TARGETDEPS += ../CCSSH/debug/libCCSSH.a
unix:LIBS+=../CCSSH/libCCSSH.a
unix:POST_TARGETDEPS += ../CCSSH/libCCSSH.a
Hope that helps.
Kind regards,
Patrick Vollebregt
Developer
CrossCode - http://www.crosscode.nl
> 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:
>
> The example consists of three projects: Two static libs and one simple
> project with a main function. testlibone contains nothing but a
> function in a namespace. testlibtwo contains a single class definition
> calls that function in one of its class methods. The main function
> calls the method in testlibtwo's class.
>
> When compiling the testprogram.pro file (which contains the main
> function) I get the following linking error:
>
> /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?
>
> testlibone.pro:
>
> QT -= core \
> gui
> TARGET = testlibone
> TEMPLATE = lib
> CONFIG += staticlib
>
> HEADERS += testfunctions.h
> SOURCES += testfunctions.cpp
>
> testfunctions.h:
>
> #ifndef __TESTFUNCTIONS_H
> #define __TESTFUNCTIONS_H
>
> namespace TestFunctions
> {
> void DoSomethingToAnInt( int& an_int );
> };
>
> #endif // __TESTFUNCTIONS_H
>
> testfunctions.cpp:
>
> #include "testfunctions.h"
>
> void TestFunctions::DoSomethingToAnInt( int& an_int )
> {
> if( an_int == 0 )
> {
> ++an_int;
> }
> else
> {
> an_int = 15;
> }
> }
>
> testlibtwo.pro:
>
> QT -= core \
> gui
> TARGET = testlibtwo
> TEMPLATE = lib
> CONFIG += staticlib
>
> HEADERS += testclass.h
> SOURCES += testclass.cpp
>
> LIBS += -L../testlibone -ltestlibone
> INCLUDEPATH += ../testlibone
>
>
> testclass.cpp:
>
> #include "testclass.h"
> #include "testfunctions.h"
>
> testprogram.pro
>
> QT -= core \
> gui
>
> LIBS += -L../testlibone -ltestlibone \
> -L../testlibtwo -ltestlibtwo
> INCLUDEPATH += ../testlibone \
> ../testlibtwo
>
> SOURCES += main.cpp
>
> main.cpp:
>
> #include "testclass.h"
> #include "testfunctions.h"
>
More information about the Qt-interest-old
mailing list