| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the documentation of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | /*!
|
|---|
| 43 | \page qt-embedded-crosscompiling.html
|
|---|
| 44 |
|
|---|
| 45 | \title Cross-Compiling Qt for Embedded Linux Applications
|
|---|
| 46 | \ingroup qt-embedded-linux
|
|---|
| 47 |
|
|---|
| 48 | Cross-compiling is the process of compiling an application on one
|
|---|
| 49 | machine, producing executable code for a different machine or
|
|---|
| 50 | device. To cross-compile a \l{Qt for Embedded Linux} application,
|
|---|
| 51 | use the following approach:
|
|---|
| 52 |
|
|---|
| 53 | \tableofcontents
|
|---|
| 54 |
|
|---|
| 55 | \note The cross-compiling procedure has the configuration
|
|---|
| 56 | process in common with the installation procedure; i.e., you might
|
|---|
| 57 | not necessarily have to perform all the mentioned actions
|
|---|
| 58 | depending on your current configuration.
|
|---|
| 59 |
|
|---|
| 60 | \section1 Step 1: Set the Cross-Compiler's Path
|
|---|
| 61 |
|
|---|
| 62 | Specify which cross-compiler to use by setting the \c PATH
|
|---|
| 63 | environment variable. For example, if the current shell is bash,
|
|---|
| 64 | ksh, zsh or sh:
|
|---|
| 65 |
|
|---|
| 66 | \snippet doc/src/snippets/code/doc_src_emb-crosscompiling.qdoc 0
|
|---|
| 67 |
|
|---|
| 68 | \section1 Step 2: Create a Target Specific qmake Specification
|
|---|
| 69 |
|
|---|
| 70 | The qmake tool requires a platform and compiler specific \c
|
|---|
| 71 | qmake.conf file describing the various default values, to generate
|
|---|
| 72 | the appropriate Makefiles. The standard \l{Qt for Embedded Linux}
|
|---|
| 73 | distribution provides such files for several combinations of
|
|---|
| 74 | platforms and compilers. These files are located in the
|
|---|
| 75 | distribution's \c mkspecs/qws subdirectory.
|
|---|
| 76 |
|
|---|
| 77 | Each platform has a default specification. \l{Qt for Embedded Linux} will
|
|---|
| 78 | use the default specification for the current platform unless told
|
|---|
| 79 | otherwise. To override this behavior, you can use the \c configure
|
|---|
| 80 | script's \c -platform option to change the specification for the host
|
|---|
| 81 | platform (where compilation will take place).
|
|---|
| 82 |
|
|---|
| 83 | The \c configure script's \c -xplatform option is used to provide a
|
|---|
| 84 | specification for the target architecture (where the library will be
|
|---|
| 85 | deployed).
|
|---|
| 86 |
|
|---|
| 87 | For example, to cross-compile an application to run on a device with
|
|---|
| 88 | an ARM architecture, using the GCC toolchain, run the configure
|
|---|
| 89 | script at the command line in the following way:
|
|---|
| 90 |
|
|---|
| 91 | \snippet doc/src/snippets/code/doc_src_emb-crosscompiling.qdoc 1
|
|---|
| 92 |
|
|---|
| 93 | If neither of the provided specifications fits your target device,
|
|---|
| 94 | you can create your own. To create a custom \c qmake.conf file,
|
|---|
| 95 | just copy and customize an already existing file. For example:
|
|---|
| 96 |
|
|---|
| 97 | \snippet doc/src/snippets/code/doc_src_emb-crosscompiling.qdoc 2
|
|---|
| 98 |
|
|---|
| 99 | \note When defining a mkspec for a Linux target, the directory must
|
|---|
| 100 | be prefixed with "linux-". We recommend that you copy the entire
|
|---|
| 101 | directory.
|
|---|
| 102 |
|
|---|
| 103 | Note also that when providing you own qmake specifcation, you must
|
|---|
| 104 | use the \c configure script's \c -xplatform option to make
|
|---|
| 105 | \l{Qt for Embedded Linux} aware of the custom \c qmake.conf file.
|
|---|
| 106 |
|
|---|
| 107 | \section1 Step 3: Provide Architecture Specific Files
|
|---|
| 108 |
|
|---|
| 109 | Starting with Qt 4, all of Qt's implicitly shared classes can
|
|---|
| 110 | safely be copied across threads like any other value classes,
|
|---|
| 111 | i.e., they are fully reentrant. This is accomplished by
|
|---|
| 112 | implementing reference counting operations using atomic hardware
|
|---|
| 113 | instructions on all the different platforms supported by Qt.
|
|---|
| 114 |
|
|---|
| 115 | To support a new architecture, it is important to ensure that
|
|---|
| 116 | these platform-specific atomic operations are implemented in a
|
|---|
| 117 | corresponding header file (\c qatomic_ARCH.h), and that this file
|
|---|
| 118 | is located in Qt's \c src/corelib/arch directory. For example, the
|
|---|
| 119 | Intel 80386 implementation is located in \c
|
|---|
| 120 | src/corelib/arch/qatomic_i386.h.
|
|---|
| 121 |
|
|---|
| 122 | See the \l {Implementing Atomic Operations} documentation for
|
|---|
| 123 | details.
|
|---|
| 124 |
|
|---|
| 125 | \section1 Step 4: Provide Hardware Drivers
|
|---|
| 126 |
|
|---|
| 127 | Without the proper mouse and keyboard drivers, you will not be
|
|---|
| 128 | able to give any input to your application when it is installed on
|
|---|
| 129 | the target device. You must also ensure that the appropriate
|
|---|
| 130 | screen driver is present to make the server process able to put
|
|---|
| 131 | the application's widgets on screen.
|
|---|
| 132 |
|
|---|
| 133 | \l{Qt for Embedded Linux} provides several ready-made mouse, keyboard and
|
|---|
| 134 | screen drivers, see the \l{Qt for Embedded Linux Pointer Handling}{pointer
|
|---|
| 135 | handling}, \l{Qt for Embedded Linux Character Input}{character input} and
|
|---|
| 136 | \l{Qt for Embedded Linux Display Management}{display management}
|
|---|
| 137 | documentation for details.
|
|---|
| 138 |
|
|---|
| 139 | In addition, custom drivers can be added by deriving from the
|
|---|
| 140 | QWSMouseHandler, QWSKeyboardHandler and QScreen classes
|
|---|
| 141 | respectively, and by creating corresponding plugins to make use of
|
|---|
| 142 | Qt's plugin mechanism (dynamically loading the drivers into the
|
|---|
| 143 | server application at runtime). Note that the plugins must be
|
|---|
| 144 | located in a location where Qt will look for plugins, e.g., the
|
|---|
| 145 | standard \c plugin directory.
|
|---|
| 146 |
|
|---|
| 147 | See the \l {How to Create Qt Plugins} documentation and the \l
|
|---|
| 148 | {tools/plugandpaint}{Plug & Paint} example for details.
|
|---|
| 149 |
|
|---|
| 150 | \section1 Step 5: Build the Target Specific Executable
|
|---|
| 151 |
|
|---|
| 152 | Before building the executable, you must specify the target
|
|---|
| 153 | architecture as well as the target specific hardware drivers by
|
|---|
| 154 | running the \c configure script:
|
|---|
| 155 |
|
|---|
| 156 | \snippet doc/src/snippets/code/doc_src_emb-crosscompiling.qdoc 3
|
|---|
| 157 |
|
|---|
| 158 | It is also important to make sure that all the third party
|
|---|
| 159 | libraries that the application and the Qt libraries require, are
|
|---|
| 160 | present in the tool chain. In particular, if the zlib and jpeg
|
|---|
| 161 | libraries are not available, they must be included by running the
|
|---|
| 162 | \c configure script with the \c -L and \c -I options. For example:
|
|---|
| 163 |
|
|---|
| 164 | \snippet doc/src/snippets/code/doc_src_emb-crosscompiling.qdoc 4
|
|---|
| 165 |
|
|---|
| 166 | The JPEG source can be downloaded from \l http://www.ijg.org/. The
|
|---|
| 167 | \l{Qt for Embedded Linux} distribution includes a version of the zlib source
|
|---|
| 168 | that can be compiled into the Qt for Embedded Linux library. If integrators
|
|---|
| 169 | wish to use a later version of the zlib library, it can be
|
|---|
| 170 | downloaded from the \l http://www.gzip.org/zlib/ website.
|
|---|
| 171 |
|
|---|
| 172 | Then build the executable:
|
|---|
| 173 |
|
|---|
| 174 | \snippet doc/src/snippets/code/doc_src_emb-crosscompiling.qdoc 5
|
|---|
| 175 |
|
|---|
| 176 | That's all. Your target specific executable is ready for deployment.
|
|---|
| 177 |
|
|---|
| 178 | \table 100%
|
|---|
| 179 | \row
|
|---|
| 180 | \o \bold {See also:}
|
|---|
| 181 |
|
|---|
| 182 | \l{Qt for Embedded Linux Architecture} and \l{Deploying Qt for Embedded Linux
|
|---|
| 183 | Applications}.
|
|---|
| 184 |
|
|---|
| 185 | \row
|
|---|
| 186 | \o \bold{Third party resources:}
|
|---|
| 187 |
|
|---|
| 188 | \l{http://silmor.de/29}{Cross compiling Qt/Win Apps on Linux} covers the
|
|---|
| 189 | process of cross-compiling Windows applications on Linux.
|
|---|
| 190 | \endtable
|
|---|
| 191 | */
|
|---|