PDA

View Full Version : Using a static library



Cruz
26th January 2010, 14:22
Hello!

I'm a total lamer when it comes to compiling and using libraries. Can anyone please put me on the right track? I have a Qt Project in Eclipse on Linux and so far everything compiles and works great. I want to use the newmat library for matrix operations. So I added the newmat sources to my source tree and compiled the package using the provided make files and now I have a libnewmat.a file that is supposed to be the library. How do I use this library now?

In my source code I included

#include <newmat/newmat.h>

and because of this all the newmat source are recompiled each time I build my Qt project. I tried adding the library in project preferences -> C/C++ project paths -> libraries, but it doesn't change anything. What do I have to do?

Thanks
Cruz

Archimedes
26th January 2010, 15:41
What you probably want is to dynamic compile the newmat library (.so) and use in your project the QLibrary class to load it.

schnitzel
26th January 2010, 17:00
you just add this to your .pro file:

for windows:
LIBS += path/to/your/lib/libnewmat.a

for unix:

LIBS += -L/usr/local/lib -lnewmat

Make sure you put that new lib in /usr/local/lib for the example above.

I find it useful to do the following command on the final executable:

ldd ./mynewapp

this will give you a list of all libs the app needs and whether it was able to find them all.