PDA

View Full Version : Using external libraries



Handi
30th July 2010, 20:36
Hello, I'm working in Qt Creator/Win7, and have been trying to understand how to use external libraries for 2 hours already.

I've read the qmake documentation and looked for info on google but I didn't find any satisfactory examples.

I've added qextserialportd.dll and qwt5.dll files to my main directory where all the project files are.

here is my .pro file:

QT += core gui

TARGET = myser2
TEMPLATE = app


SOURCES += main.cpp\
myser2.cpp

HEADERS += myser2.h

FORMS += myser2.ui

LIBS += -lqextserialportd
LIBS += -lqwt5


in myser2.h, I've put

#include <qextserialport.h>
#include <qwt_plot.h>

now, when I try to build, it can't find any of those files.
I've tried all sorts of different notations for LIBS:

LIBS += <path>/qwt5.lib
LIBS += <path>/qwt5.dll
LIBS += qwt5.lib
LIBS += -L<path> -lqwt5
but nothing works

If you could explain me what I am forgetting, that would be great. An example project would be even better.
Thanks

hobbyist
30th July 2010, 20:49
Hi,

Use INCLUDEPATH to define the location of your header files, LIBPATH to define the location of your libraries, and LIBS to define the libs. For example

INCLUDEPATH += c:\qwt\include
LIBPATH += c:\qwt\lib
LIBS += -lqwt5

Hope this helps.

Handi
30th July 2010, 21:48
Thanks, but my libs are in the same folder as all my project files which is:

C:\Users\Pavel\Desktop\Pavel\Programs\Qt\myser2

I tried to add

INCLUDEPATH += C:\Users\Pavel\Desktop\Pavel\Programs\Qt\myser2
LIBPATH += C:\Users\Pavel\Desktop\Pavel\Programs\Qt\myser2

or

INCLUDEPATH += .
LIBPATH += .


but it doesn't work. I put my project on rapidshare (qtcentre has a 244k limit for zip files :(), maybe you could take a look:
http://rapidshare.com/files/410065957/myser2.zip

EDIT: Btw, when I include compiled libraries to my project, I do not need to also include all the header files that were used to compile that library, do I?
For instance, when I include qextserialport.h, does it look for it inside qextserialportd.dll or not?

baluk
9th December 2010, 22:18
Hi Handi,

I am getting the same error. i am wondering if you have overcome the problem. If so please let me know the solution.

SixDegrees
9th December 2010, 22:42
Hi Handi,

I am getting the same error. i am wondering if you have overcome the problem. If so please let me know the solution.

What error? The only thing mentioned above is that something "can't find any of those files" or "it doesn't work." An actual error message would be quite helpful, but I don't see any. At a minimum, it would illuminate whether the problem is an inability to locate the header files or the library files.

ChrisW67
9th December 2010, 22:51
To quote and repair an earlier answer in this thread.

At compile time:

Use INCLUDEPATH to define extra locations to be searched for header files
Use LIBS -L options to define extra locations to be searched for libraries
Use LIBS -l options to name the libs to be used.

Example:


INCLUDEPATH += /home/me/foo/include
LIBS += -L/home/me/foo/lib -lfoo


At run time the dynamically loadable libraries must be locatable by the operating system:

On Windows: In the current working directory of the executing process (note that this is rarely the same as the source code directory) or on the system PATH.
On Linux: In directories listed in the LD_LIBRARY_PATH environment variable (if it exists) and on the system library path (see /etc/ld.so.conf). See man ld.so for other, less used options.
On Mac OS X: Probably similar to Linux but bound to be different in detail.