1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \page deployment.html
|
---|
30 | \title Deploying Qt Applications
|
---|
31 |
|
---|
32 | Deploying an Qt application does not require any C++
|
---|
33 | programming. All you need to do is to build Qt and your
|
---|
34 | application in release mode, following the procedures described in
|
---|
35 | this documentation. We will demonstrate the procedures in terms of
|
---|
36 | deploying the \l {tools/plugandpaint}{Plug & Paint} application
|
---|
37 | that is provided in Qt's examples directory.
|
---|
38 |
|
---|
39 | \section1 Static vs. Shared Libraries
|
---|
40 |
|
---|
41 | There are two ways of deploying an application:
|
---|
42 |
|
---|
43 | \list
|
---|
44 | \o Static Linking
|
---|
45 | \o Shared Libraries (Frameworks on Mac)
|
---|
46 | \endlist
|
---|
47 |
|
---|
48 | Static linking results in a stand-alone executable. The advantage
|
---|
49 | is that you will only have a few files to deploy. The
|
---|
50 | disadvantages are that the executables are large and with no
|
---|
51 | flexibility (i.e a new version of the application, or of Qt, will
|
---|
52 | require that the deployment process is repeated), and that you
|
---|
53 | cannot deploy plugins.
|
---|
54 |
|
---|
55 | To deploy plugin-based applications, you can use the shared
|
---|
56 | library approach. Shared libraries also provide smaller, more
|
---|
57 | flexible executables. For example, using the shared library
|
---|
58 | approach, the user is able to independently upgrade the Qt library
|
---|
59 | used by the application.
|
---|
60 |
|
---|
61 | Another reason why you might want to use the shared library
|
---|
62 | approach, is if you want to use the same Qt libraries for a family
|
---|
63 | of applications. In fact, if you download the binary installation
|
---|
64 | of Qt, you get Qt as a shared library.
|
---|
65 |
|
---|
66 | The disadvantage with the shared library approach is that you
|
---|
67 | will get more files to deploy. For more information, see
|
---|
68 | \l{sharedlibrary.html}{Creating Shared Libraries}.
|
---|
69 |
|
---|
70 | \section1 Deploying Qt's Libraries
|
---|
71 |
|
---|
72 | \table
|
---|
73 | \header
|
---|
74 | \o {4,1} Qt's Libraries
|
---|
75 | \row
|
---|
76 | \o \l {QAxContainer}
|
---|
77 | \o \l {QAxServer}
|
---|
78 | \o \l {QtCore}
|
---|
79 | \o \l {QtDBus}
|
---|
80 | \row
|
---|
81 | \o \l {QtDesigner}
|
---|
82 | \o \l {QtGui}
|
---|
83 | \o \l {QtHelp}
|
---|
84 | \o \l {QtNetwork}
|
---|
85 | \row
|
---|
86 | \o \l {QtOpenGL}
|
---|
87 | \o \l {QtScript}
|
---|
88 | \o \l {QtScriptTools}
|
---|
89 | \o \l {QtSql}
|
---|
90 | \row
|
---|
91 | \o \l {QtSvg}
|
---|
92 | \o \l {QtWebKit}
|
---|
93 | \o \l {QtXml}
|
---|
94 | \o \l {QtXmlPatterns}
|
---|
95 | \row
|
---|
96 | \o \l {Phonon Module}{Phonon}
|
---|
97 | \o \l {Qt3Support}
|
---|
98 | \endtable
|
---|
99 |
|
---|
100 | Since Qt is not a system library, it has to be redistributed along
|
---|
101 | with your application; the minimum is to redistribute the run-time
|
---|
102 | of the libraries used by the application. Using static linking,
|
---|
103 | however, the Qt run-time is compiled into the executable.
|
---|
104 |
|
---|
105 | In general, you should deploy all plugins that your build of Qt uses,
|
---|
106 | excluding only those that you have identified as being unnecessary
|
---|
107 | for your application and its users.
|
---|
108 |
|
---|
109 | For instance, you may need to deploy plugins for JPEG support and
|
---|
110 | SQL drivers, but you should also deploy plugins that your users may
|
---|
111 | require, including those for accessibility.
|
---|
112 | For more information about plugins, see the
|
---|
113 | \l{plugins-howto.html}{How to Create Qt Plugins} documentation.
|
---|
114 |
|
---|
115 | When deploying an application using the shared library approach
|
---|
116 | you must ensure that the Qt libraries will use the correct path to
|
---|
117 | find the Qt plugins, documentation, translation etc. To do this you
|
---|
118 | can use a \c qt.conf file. For more information, see the \l {Using
|
---|
119 | qt.conf} documentation.
|
---|
120 |
|
---|
121 | Depending on configuration, compiler specific libraries must be
|
---|
122 | redistributed as well. For more information, see the platform
|
---|
123 | specific Application Dependencies sections: \l
|
---|
124 | {deployment-x11.html#application-dependencies}{X11}, \l
|
---|
125 | {deployment-windows.html#application-dependencies}{Windows}, \l
|
---|
126 | {deployment-mac.html#application-dependencies}{Mac}.
|
---|
127 |
|
---|
128 | \section1 Licensing
|
---|
129 |
|
---|
130 | Some of Qt's libraries are based on third party libraries that are
|
---|
131 | not licensed using the same dual-license model as Qt. As a result,
|
---|
132 | care must be taken when deploying applications that use these
|
---|
133 | libraries, particularly when the application is statically linked
|
---|
134 | to them.
|
---|
135 |
|
---|
136 | The following table contains an inexhaustive summary of the issues
|
---|
137 | you should be aware of.
|
---|
138 |
|
---|
139 | \table
|
---|
140 | \header \o Qt Library \o Dependency
|
---|
141 | \o Licensing Issue
|
---|
142 | \row \o QtHelp \o CLucene
|
---|
143 | \o The version of clucene distributed with Qt is licensed
|
---|
144 | under the GNU LGPL version 2.1 or later. This has implications for
|
---|
145 | developers of closed source applications. Please see
|
---|
146 | \l{QtHelp Module#License Information}{the QtHelp module documentation}
|
---|
147 | for more information.
|
---|
148 |
|
---|
149 | \row \o QtNetwork \o OpenSSL
|
---|
150 | \o Some configurations of QtNetwork use OpenSSL at run-time. Deployment
|
---|
151 | of OpenSSL libraries is subject to both licensing and export restrictions.
|
---|
152 | More information can be found in the \l{Secure Sockets Layer (SSL) Classes}
|
---|
153 | documentation.
|
---|
154 |
|
---|
155 | \row \o QtWebKit \o WebKit
|
---|
156 | \o WebKit is licensed under the GNU LGPL version 2 or later.
|
---|
157 | This has implications for developers of closed source applications.
|
---|
158 | Please see \l{WebKit in Qt#License Information}{the QtWebKit module
|
---|
159 | documentation} for more information.
|
---|
160 |
|
---|
161 | \row \o \l{Phonon Module}{Phonon} \o Phonon
|
---|
162 | \o Phonon relies on the native multimedia engines on different platforms.
|
---|
163 | Phonon itself is licensed under the GNU LGPL version 2. Please see
|
---|
164 | \l{Phonon Module#License Information}{the Phonon module documentation}
|
---|
165 | for more information on licensing and the
|
---|
166 | \l{Phonon Overview#Backends}{Phonon Overview} for details of the backends
|
---|
167 | in use on different platforms.
|
---|
168 | \endtable
|
---|
169 |
|
---|
170 | \section1 Platform-Specific Notes
|
---|
171 |
|
---|
172 | The procedure of deploying Qt applications is different for the
|
---|
173 | various platforms:
|
---|
174 |
|
---|
175 | \list
|
---|
176 | \o \l{Deploying an Application on X11 Platforms}{Qt for X11 Platforms}
|
---|
177 | \o \l{Deploying an Application on Windows}{Qt for Windows}
|
---|
178 | \o \l{Deploying an Application on Mac OS X}{Qt for Mac OS X}
|
---|
179 | \o \l{Deploying Qt for Embedded Linux Applications}{Qt for Embedded Linux}
|
---|
180 | \o \l{Deploying an Application on the Symbian platform}{Qt for the Symbian platform}
|
---|
181 | \endlist
|
---|
182 |
|
---|
183 | \sa Installation {Platform-Specific Documentation}
|
---|
184 | */
|
---|
185 |
|
---|
186 | /*!
|
---|
187 | \page deployment-x11.html
|
---|
188 | \contentspage Deploying Qt Applications
|
---|
189 |
|
---|
190 | \title Deploying an Application on X11 Platforms
|
---|
191 |
|
---|
192 | Due to the proliferation of Unix systems (commercial Unices, Linux
|
---|
193 | distributions, etc.), deployment on Unix is a complex
|
---|
194 | topic. Before we start, be aware that programs compiled for one
|
---|
195 | Unix flavor will probably not run on a different Unix system. For
|
---|
196 | example, unless you use a cross-compiler, you cannot compile your
|
---|
197 | application on Irix and distribute it on AIX.
|
---|
198 |
|
---|
199 | Contents:
|
---|
200 |
|
---|
201 | \tableofcontents
|
---|
202 |
|
---|
203 | This documentation will describe how to determine which files you
|
---|
204 | should include in your distribution, and how to make sure that the
|
---|
205 | application will find them at run-time. We will demonstrate the
|
---|
206 | procedures in terms of deploying the \l {tools/plugandpaint}{Plug
|
---|
207 | & Paint} application that is provided in Qt's examples directory.
|
---|
208 |
|
---|
209 | \section1 Static Linking
|
---|
210 |
|
---|
211 | Static linking is often the safest and easiest way to distribute
|
---|
212 | an application on Unix since it relieves you from the task of
|
---|
213 | distributing the Qt libraries and ensuring that they are located
|
---|
214 | in the default search path for libraries on the target system.
|
---|
215 |
|
---|
216 | \section2 Building Qt Statically
|
---|
217 |
|
---|
218 | To use this approach, you must start by installing a static version
|
---|
219 | of the Qt library:
|
---|
220 |
|
---|
221 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 0
|
---|
222 |
|
---|
223 | We specify the prefix so that we do not overwrite the existing Qt
|
---|
224 | installation. The example above only builds the Qt libraries,
|
---|
225 | i.e. the examples and Qt Designer will not be built. When \c make
|
---|
226 | is done, you will find the Qt libraries in the \c /path/to/Qt/lib
|
---|
227 | directory.
|
---|
228 |
|
---|
229 | When linking your application against static Qt libraries, note
|
---|
230 | that you might need to add more libraries to the \c LIBS line in
|
---|
231 | your project file. For more information, see the \l {Application
|
---|
232 | Dependencies} section.
|
---|
233 |
|
---|
234 | \section2 Linking the Application to the Static Version of Qt
|
---|
235 |
|
---|
236 | Once Qt is built statically, the next step is to regenerate the
|
---|
237 | makefile and rebuild the application. First, we must go into the
|
---|
238 | directory that contains the application:
|
---|
239 |
|
---|
240 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 1
|
---|
241 |
|
---|
242 | Now run qmake to create a new makefile for the application, and do
|
---|
243 | a clean build to create the statically linked executable:
|
---|
244 |
|
---|
245 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 2
|
---|
246 |
|
---|
247 | You probably want to link against the release libraries, and you
|
---|
248 | can specify this when invoking \c qmake. Note that we must set the
|
---|
249 | path to the static Qt that we just built.
|
---|
250 |
|
---|
251 | To check that the application really links statically with Qt, run
|
---|
252 | the \c ldd tool (available on most Unices):
|
---|
253 |
|
---|
254 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 3
|
---|
255 |
|
---|
256 | Verify that the Qt libraries are not mentioned in the output.
|
---|
257 |
|
---|
258 | Now, provided that everything compiled and linked without any
|
---|
259 | errors, we should have a \c plugandpaint file that is ready for
|
---|
260 | deployment. One easy way to check that the application really can
|
---|
261 | be run stand-alone is to copy it to a machine that doesn't have Qt
|
---|
262 | or any Qt applications installed, and run it on that machine.
|
---|
263 |
|
---|
264 | Remember that if your application depends on compiler specific
|
---|
265 | libraries, these must still be redistributed along with your
|
---|
266 | application. For more information, see the \l {Application
|
---|
267 | Dependencies} section.
|
---|
268 |
|
---|
269 | The \l {tools/plugandpaint}{Plug & Paint} example consists of
|
---|
270 | several components: The core application (\l
|
---|
271 | {tools/plugandpaint}{Plug & Paint}), and the \l
|
---|
272 | {tools/plugandpaintplugins/basictools}{Basic Tools} and \l
|
---|
273 | {tools/plugandpaintplugins/extrafilters}{Extra Filters}
|
---|
274 | plugins. Since we cannot deploy plugins using the static linking
|
---|
275 | approach, the executable we have prepared so far is
|
---|
276 | incomplete. The application will run, but the functionality will
|
---|
277 | be disabled due to the missing plugins. To deploy plugin-based
|
---|
278 | applications we should use the shared library approach.
|
---|
279 |
|
---|
280 | \section1 Shared Libraries
|
---|
281 |
|
---|
282 | We have two challenges when deploying the \l
|
---|
283 | {tools/plugandpaint}{Plug & Paint} application using the shared
|
---|
284 | libraries approach: The Qt runtime has to be correctly
|
---|
285 | redistributed along with the application executable, and the
|
---|
286 | plugins have to be installed in the correct location on the target
|
---|
287 | system so that the application can find them.
|
---|
288 |
|
---|
289 | \section2 Building Qt as a Shared Library
|
---|
290 |
|
---|
291 | We assume that you already have installed Qt as a shared library,
|
---|
292 | which is the default when installing Qt, in the \c /path/to/Qt
|
---|
293 | directory. For more information on how to build Qt, see the \l
|
---|
294 | {Installation} documentation.
|
---|
295 |
|
---|
296 | \section2 Linking the Application to Qt as a Shared Library
|
---|
297 |
|
---|
298 | After ensuring that Qt is built as a shared library, we can build
|
---|
299 | the \l {tools/plugandpaint}{Plug & Paint} application. First, we
|
---|
300 | must go into the directory that contains the application:
|
---|
301 |
|
---|
302 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 4
|
---|
303 |
|
---|
304 | Now run qmake to create a new makefile for the application, and do
|
---|
305 | a clean build to create the dynamically linked executable:
|
---|
306 |
|
---|
307 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 5
|
---|
308 |
|
---|
309 | This builds the core application, the following will build the
|
---|
310 | plugins:
|
---|
311 |
|
---|
312 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 6
|
---|
313 |
|
---|
314 | If everything compiled and linked without any errors, we will get
|
---|
315 | a \c plugandpaint executable and the \c libpnp_basictools.so and
|
---|
316 | \c libpnp_extrafilters.so plugin files.
|
---|
317 |
|
---|
318 | \section2 Creating the Application Package
|
---|
319 |
|
---|
320 | There is no standard package management on Unix, so the method we
|
---|
321 | present below is a generic solution. See the documentation for
|
---|
322 | your target system for information on how to create a package.
|
---|
323 |
|
---|
324 | To deploy the application, we must make sure that we copy the
|
---|
325 | relevant Qt libraries (corresponding to the Qt modules used in the
|
---|
326 | application) as well as the executable to the same
|
---|
327 | directory. Remember that if your application depends on compiler
|
---|
328 | specific libraries, these must also be redistributed along with
|
---|
329 | your application. For more information, see the \l {Application
|
---|
330 | Dependencies} section.
|
---|
331 |
|
---|
332 | We'll cover the plugins shortly, but the main issue with shared
|
---|
333 | libraries is that you must ensure that the dynamic linker will
|
---|
334 | find the Qt libraries. Unless told otherwise, the dynamic linker
|
---|
335 | doesn't search the directory where your application resides. There
|
---|
336 | are many ways to solve this:
|
---|
337 |
|
---|
338 | \list
|
---|
339 |
|
---|
340 | \o You can install the Qt libraries in one of the system
|
---|
341 | library paths (e.g. \c /usr/lib on most systems).
|
---|
342 |
|
---|
343 | \o You can pass a predetermined path to the \c -rpath command-line
|
---|
344 | option when linking the application. This will tell the dynamic
|
---|
345 | linker to look in this directory when starting your application.
|
---|
346 |
|
---|
347 | \o You can write a startup script for your application, where you
|
---|
348 | modify the dynamic linker configuration (e.g. adding your
|
---|
349 | application's directory to the \c LD_LIBRARY_PATH environment
|
---|
350 | variable. \note If your application will be running with "Set
|
---|
351 | user ID on execution," and if it will be owned by root, then
|
---|
352 | LD_LIBRARY_PATH will be ignored on some platforms. In this
|
---|
353 | case, use of the LD_LIBRARY_PATH approach is not an option).
|
---|
354 |
|
---|
355 | \endlist
|
---|
356 |
|
---|
357 | The disadvantage of the first approach is that the user must have
|
---|
358 | super user privileges. The disadvantage of the second approach is
|
---|
359 | that the user may not have privileges to install into the
|
---|
360 | predetemined path. In either case, the users don't have the option
|
---|
361 | of installing to their home directory. We recommend using the
|
---|
362 | third approach since it is the most flexible. For example, a \c
|
---|
363 | plugandpaint.sh script will look like this:
|
---|
364 |
|
---|
365 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 7
|
---|
366 |
|
---|
367 | By running this script instead of the executable, you are sure
|
---|
368 | that the Qt libraries will be found by the dynamic linker. Note
|
---|
369 | that you only have to rename the script to use it with other
|
---|
370 | applications.
|
---|
371 |
|
---|
372 | When looking for plugins, the application searches in a plugins
|
---|
373 | subdirectory inside the directory of the application
|
---|
374 | executable. Either you have to manually copy the plugins into the
|
---|
375 | \c plugins directory, or you can set the \c DESTDIR in the
|
---|
376 | plugins' project files:
|
---|
377 |
|
---|
378 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 8
|
---|
379 |
|
---|
380 | An archive distributing all the Qt libraries, and all the plugins,
|
---|
381 | required to run the \l {tools/plugandpaint}{Plug & Paint}
|
---|
382 | application, would have to include the following files:
|
---|
383 |
|
---|
384 | \table 100%
|
---|
385 | \header
|
---|
386 | \o Component \o {2, 1} File Name
|
---|
387 | \row
|
---|
388 | \o The executable
|
---|
389 | \o {2, 1} \c plugandpaint
|
---|
390 | \row
|
---|
391 | \o The script to run the executable
|
---|
392 | \o {2, 1} \c plugandpaint.sh
|
---|
393 | \row
|
---|
394 | \o The Basic Tools plugin
|
---|
395 | \o {2, 1} \c plugins\libpnp_basictools.so
|
---|
396 | \row
|
---|
397 | \o The ExtraFilters plugin
|
---|
398 | \o {2, 1} \c plugins\libpnp_extrafilters.so
|
---|
399 | \row
|
---|
400 | \o The Qt Core module
|
---|
401 | \o {2, 1} \c libQtCore.so.4
|
---|
402 | \row
|
---|
403 | \o The Qt GUI module
|
---|
404 | \o {2, 1} \c libQtGui.so.4
|
---|
405 | \endtable
|
---|
406 |
|
---|
407 | On most systems, the extension for shared libraries is \c .so. A
|
---|
408 | notable exception is HP-UX, which uses \c .sl.
|
---|
409 |
|
---|
410 | Remember that if your application depends on compiler specific
|
---|
411 | libraries, these must still be redistributed along with your
|
---|
412 | application. For more information, see the \l {Application
|
---|
413 | Dependencies} section.
|
---|
414 |
|
---|
415 | To verify that the application now can be successfully deployed,
|
---|
416 | you can extract this archive on a machine without Qt and without
|
---|
417 | any compiler installed, and try to run it, i.e. run the \c
|
---|
418 | plugandpaint.sh script.
|
---|
419 |
|
---|
420 | An alternative to putting the plugins in the \c plugins
|
---|
421 | subdirectory is to add a custom search path when you start your
|
---|
422 | application using QApplication::addLibraryPath() or
|
---|
423 | QApplication::setLibraryPaths().
|
---|
424 |
|
---|
425 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 9
|
---|
426 |
|
---|
427 | \section1 Application Dependencies
|
---|
428 |
|
---|
429 | \section2 Additional Libraries
|
---|
430 |
|
---|
431 | To find out which libraries your application depends on, run the
|
---|
432 | \c ldd tool (available on most Unices):
|
---|
433 |
|
---|
434 | \snippet doc/src/snippets/code/doc_src_deployment.qdoc 10
|
---|
435 |
|
---|
436 | This will list all the shared library dependencies for your
|
---|
437 | application. Depending on configuration, these libraries must be
|
---|
438 | redistributed along with your application. In particular, the
|
---|
439 | standard C++ library must be redistributed if you're compiling
|
---|
440 | your application with a compiler that is binary incompatible with
|
---|
441 | the system compiler. When possible, the safest solution is to link
|
---|
442 | against these libraries statically.
|
---|
443 |
|
---|
444 | You will probably want to link dynamically with the regular X11
|
---|
445 | libraries, since some implementations will try to open other
|
---|
446 | shared libraries with \c dlopen(), and if this fails, the X11
|
---|
447 | library might cause your application to crash.
|
---|
448 |
|
---|
449 | It's also worth mentioning that Qt will look for certain X11
|
---|
450 | extensions, such as Xinerama and Xrandr, and possibly pull them
|
---|
451 | in, including all the libraries that they link against. If you
|
---|
452 | can't guarantee the presence of a certain extension, the safest
|
---|
|
---|