Kristoffer
Kristoffer

Reputation: 13

Qt Creator and static libraries

I'm quite a newbie with C++ and maybe that's a very stupid question, but how do one include a header from a static linked library?

I've created a static library in Qt Creator with the following .pro file:

QT -= gui
TARGET = Foobar
TEMPLATE = lib
CONFIG += staticlib

SOURCES += thefoobar.cpp \
    sub/subbar.cpp

HEADERS += thefoobar.h \
    sub/subbar.h

compiled it and put the resulting libFoobar.a into the "extstaticlibs" folder of my target project.

In my target projects .pro file i've added the following lines:

LIBS += -L$$PWD/extstaticlibs/ -lFoobar
INCLUDEPATH += $$PWD/extstaticlibs

The target project compiles without problems. But when I try to include the header thefoobar.h in one of my code files:

#include "thefoobar.h"

it always results in an error:

error: thefoobar.h: No such file or directory

Any suggestions for the correct syntax would be very much appreciated.

Kristoffer

Upvotes: 1

Views: 5924

Answers (2)

Mevin Babu
Mevin Babu

Reputation: 2475

Check where you have placed your "thefoobar.h" header file . Place it in the "extstaticlibs/" folder .

Upvotes: 1

Loebl
Loebl

Reputation: 1431

If I follow your description correctly, you ONLY put the static library into your extstaticlibs directory. You need to carry over your thefoobar.h file too. If you follow the common structure you could make:

extstaticlibs/include <- thefoobar.h goes here
extstaticlibs/lib <- libFoobar.a goes here

You then need to modify your project file like this:

LIBS += -L$$PWD/extstaticlibs/lib -lFoobar
INCLUDEPATH += $$PWD/extstaticlibs/include

Of course you can all throw it in one directory, if you want, but it may be helpful to sort things out in the beginning.

Upvotes: 1

Related Questions