Using extra libraries with a QT based program

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Using extra libraries with a QT based program

Postby nerdmaster » Wed Dec 07, 2005 3:40 pm

I was wondering if anyone can advise me about using extra libraries with a qmake based program, since I'm quite new to these aspects of programming (with most of my experience over the past 2 years being based on Java)

I'm writing a C++ based program for a computer vision project. As a result, there are a number of external (static) libraries I need, these are for the image processing and display functions. I am also planning on making the application graphical and have opted to use the QT toolkit, using qmake.

I was wondering, how do I go about importing these libraries? (bearing in mind that I don't have much experience with make)
nerdmaster
 
Posts: 52
Joined: Thu Jul 14, 2005 10:18 am

RE: Using extra libraries with a QT based program

Postby Nigel » Wed Dec 07, 2005 4:37 pm

You need to add them to the link statement in your makefile.
To link in a library called libfred.a that exists in directory /home/joe/libs (not part of $LD_LIBRARY_PATH) you would add the following two parameters to your link statement
-L /home/joe/libs -lfred

(-L adds a directory to those that will be searched for libraries, -l links in a library. The "lib" prefix and ".a" (or ".so") suffix is added by the compiler/linker.

To call routines in the library you will have to include the appropriate header file in your C++ source.
Hope this helps,

Nigel.
User avatar
Nigel
LXF regular
 
Posts: 1141
Joined: Fri Apr 08, 2005 8:03 pm
Location: Gloucestershire, UK

RE: Using extra libraries with a QT based program

Postby ChrisCook » Tue Jan 17, 2006 3:54 am

I do something like this in a project Im working on currently (http://quarkplusplus.sf.net)

In my qmake project file (*.pro) i have
Code: Select all
INCLUDEPATH += . src /usr/include/python2.4
LIBS += -lpython2.4

this lets me do somthing like
Code: Select all
#include <Python.h>

which includes the file Python.h from /usr/include/python2.4/

the final executable file will be linked with the python2.4 library which it finds from the standard library path. if the library is somewhere else like in your home directory, use
Code: Select all
LIBS += -L/home/joe/libs -lfred
as in Nigel's example.
ChrisCook
 
Posts: 1
Joined: Tue Jan 17, 2006 3:26 am


Return to Programming

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests