PDA

View Full Version : creating and using static library



indomie_seleraku
18th December 2010, 06:12
i am trying to write a static library & use it...
i have googling a lot & still not solve my prob :(
please look what i am doing & point where its goes wrong
i will explain detail here:

1. create static library
choose menu
File > New File or Project... > Other Project > C++ Library
click button Choose...
type (library) name: simple
(i uncheck QtCore in required modules for simplicity)
class name "Simple" (by default) and click button Next then Finish
a folder named simple-build-desktop will be created.

click Build and generated file will be

+ debug
+ simple.o
+ libsimple.a
+ release
+ Makefile
+ Makefile.Debug
+ Makefile.Release


(this library only keep class Simple with default constructor.. that's all)

2. Using the static library
* create a new project File > new File or Project... >Qt C++ Project > Qt Console Application named UsingLib then click Next > Finish

* copy libsimple.a to project folder (./UsingLib)

* put LIBS += ./libsimple.a or LIBS += -lsimple

* put #include <simple.h> in main.cpp

try to build but it gives error:
simple.h: No such file or directory

i also try to put libsimple.a in c:\ (c:\libsimple.a) & use these combinations:
LIBS += -Lc:/ -lsimple
LIBS += c:/libsimple.a
win32:LIBS += -Lc:/ -lsimple

none of them work :(

Lykurg
18th December 2010, 07:26
The compiler did not find the file simple.h. As the error message says... So either use INCLUDEPATH with a proper location or copy also the header file to the directory or put it in a "global" directory.

indomie_seleraku
18th December 2010, 08:05
thank you... so it need .h & .a files... i thought its only .a file.

and inside .pro file, does relative path not works here?

LIB += libsimple.a
LIB += ./libsimple.a
not working (libsimple.a inside project folder)

LIB += c:/clib/libsimple.a
works

wysota
18th December 2010, 09:05
and inside .pro file, does relative path not works here?
Use the -L parameter to point the compiler to your libraries. Also you are making a shadow build so the library is probably not in the current directory.