1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page third-party-libraries.html
\title Third Party Libraries
\brief A guide to using third party libraries with Qt
Using a third-party library with Qt is a simple process. Suppose you know
of a cross-platform library that accepts audio samples of a cat's meows and
translates them into English words. This library is named \c CatWhisperer,
and has several files that it provides as part of its library.
Your project, \c MyQtApp, stores these files in a folder named \c 3rdparty:
\list
\li MyQtApp/
\list
\li MyQtApp.pro
\li src/
\list
\li main.cpp
\endlist
\li 3rdparty/
\list
\li CatWhisperer
\list
\li include/
\list
\li CatWhisperer.h
\endlist
\li lib/
\list
\li libCatWhisperer.so
\li CatWhisperer.lib
\endlist
\li bin/
\list
\li CatWhisperer.dll
\endlist
\endlist
\endlist
\endlist
\endlist
To use the \c CatWhisperer library in \c MyQtApp, \c qmake requires the
location and names of the \c CatWhisperer libraries.
Optionally, you can also:
\list
\li Provide the location of the \c CatWhisperer source code so that you
don't have to type out the full path to each file when you include them
in your own code.
\li Choose the destination in which the \c MyQtApp executable will be
created.
\endlist
The information above is provided in the \c .pro file, so that \c qmake can
parse it and produce makefiles. Makefiles contain all the information
needed by your compiler and linker to produce output, whether it is an
executable, another library file, etc. The next sections explain the syntax
with which \c qmake expects you to provide this information.
\section1 Source Code
To be able to write
\code
#include <CatWhisperer.h>
\endcode
instead of
\code
#include <3rdparty/CatWhisperer/include/CatWhisperer.h>
\endcode
you can provide the path to the \c CatWhisperer \c include directory,
using the \l{qmake Variable Reference#INCLUDEPATH}{INCLUDEPATH} variable:
\code
INCLUDEPATH += 3rdparty/CatWhisperer/include
\endcode
\section1 Library Files
To let \c qmake know where to find the \c CatWhisperer library files,
use the \l{qmake Variable Reference#LIBS}{LIBS} variable:
\code
LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer
\endcode
The first part of the expression lets the linker know in which directory
it should look for the library files. The double quotes are only necessary
when the path contains spaces, so we could have omitted them in this
example.
The second part tells the linker which libraries to link against. We have
two different library files for UNIX platforms and Windows, respectively:
\c libCatWhisperer.so and \c CatWhisperer.lib. It is not necessary
to specify the \c .lib extension, nor the \c lib prefix
(on UNIX platforms).
\section1 Destination Directory
By default, \c qmake creates the executable in the same directory as the
\c .pro file. We can choose our own directory using the
\l{qmake Variable Reference#DESTDIR}{DESTDIR} variable:
\code
DESTDIR = bin
\endcode
That's it! You can now use the \c CatWhisperer library in your project.
The final \c .pro file looks like this:
\code
TARGET = MyQtApp
TEMPLATE = app
INCLUDEPATH += 3rdparty/CatWhisperer/include
SOURCES += src/main.cpp
LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer
\endcode
\sa {qmake Manual}, {Qt Creator: Adding Libraries to Projects}
*/
|